Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

address security findings #875

Merged
merged 4 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const { createHash } = require("crypto");

module.exports = (env) => {
const hash = createHash("md5");
const hash = createHash("sha256");
hash.update(JSON.stringify(env));

return hash.digest("hex");
Expand Down
36 changes: 33 additions & 3 deletions tools/authz/validate_ams.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@
# NOTE: require the sso.stage credentials

import os
import re
from datetime import datetime, timedelta
from http import HTTPStatus
from urllib.error import URLError
from urllib.parse import urlsplit, urlunsplit

import requests

AUTHZ_SSO_PATTERN = r"^sso.(.+\.)?redhat.com$"
AUTHZ_API_PATTERN = r"^api.(.+\.)?openshift.com$"


class AuthzURLError(URLError):
pass


class Token:
def __init__(self, client_id, client_secret) -> None:
Expand All @@ -23,11 +33,22 @@ def refresh(self) -> None:
"scope": "api.iam.access",
}

url = urlsplit(os.environ['AUTHZ_SSO_SERVER'])
url = url._replace(path="/auth/realms/redhat-external/protocol/openid-connect/token")

if not re.search(AUTHZ_SSO_PATTERN, url.netloc):
raise AuthzURLError(
f"Authz SSO URL host ('{url.netloc}') must match '{AUTHZ_SSO_PATTERN}'"
)

if url.scheme != "https":
raise AuthzURLError(f"Authz SSO URL scheme ('{url.scheme}') must be 'https'")

r = requests.post(
os.environ['AUTHZ_SSO_SERVER']
+ "/auth/realms/redhat-external/protocol/openid-connect/token",
urlunsplit(url),
data=data,
)

data = r.json()
self.access_token = data["access_token"]
expires_in = data["expires_in"]
Expand All @@ -45,8 +66,17 @@ def get(self) -> str:
def get_ams_org(rh_org_id: str) -> str:
params = {"search": f"external_id='{rh_org_id}'"}

url = urlsplit(os.environ['AUTHZ_API_SERVER'])
url = url._replace(path="/api/accounts_mgmt/v1/organizations")

if not re.search(AUTHZ_API_PATTERN, url.netloc):
raise AuthzURLError(f"Authz API URL host ('{url.netloc}') must match '{AUTHZ_API_PATTERN}'")

if url.scheme != "https":
raise AuthzURLError(f"Authz API URL scheme ('{url.scheme}') must be 'https'")

r = requests.get(
f"{os.environ['AUTHZ_API_SERVER']}/api/accounts_mgmt/v1/organizations",
urlunsplit(url),
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {my_token.get()}",
Expand Down
Loading