diff --git a/.evergreen/auth_aws/aws_tester.py b/.evergreen/auth_aws/aws_tester.py index d6ff9294..19a8b57a 100644 --- a/.evergreen/auth_aws/aws_tester.py +++ b/.evergreen/auth_aws/aws_tester.py @@ -14,7 +14,11 @@ HERE = os.path.abspath(os.path.dirname(__file__)) -sys.path.insert(0, os.path.join(HERE, 'lib')) +def join(*parts): + return os.path.join(*parts).replace(os.sep, '/') + + +sys.path.insert(0, join(HERE, 'lib')) from util import get_key as _get_key from aws_assume_role import _assume_role from aws_assume_web_role import _assume_role_with_web_identity @@ -28,7 +32,7 @@ _USE_AWS_SECRETS = False try: - with open(os.path.join(HERE, 'aws_e2e_setup.json')) as fid: + with open(join(HERE, 'aws_e2e_setup.json')) as fid: CONFIG = json.load(fid) get_key = partial(_get_key, uppercase=False) except FileNotFoundError: @@ -62,7 +66,7 @@ def setup_assume_role(): role_name = CONFIG[get_key("iam_auth_assume_role_name")] creds = _assume_role(role_name) - with open(os.path.join(HERE, 'creds.json'), 'w') as fid: + with open(join(HERE, 'creds.json'), 'w') as fid: json.dump(creds, fid) # Create the user. @@ -139,7 +143,7 @@ def setup_web_identity(): os.environ['AWS_ROLE_ARN'] = CONFIG[get_key("iam_auth_assume_web_role_name")] creds = _assume_role_with_web_identity() - with open(os.path.join(HERE, 'creds.json'), 'w') as fid: + with open(join(HERE, 'creds.json'), 'w') as fid: json.dump(creds, fid) # Create the user. diff --git a/.evergreen/auth_aws/lib/aws_handle_oidc_creds.py b/.evergreen/auth_aws/lib/aws_handle_oidc_creds.py index 9fe6f67b..ab33a858 100644 --- a/.evergreen/auth_aws/lib/aws_handle_oidc_creds.py +++ b/.evergreen/auth_aws/lib/aws_handle_oidc_creds.py @@ -105,6 +105,7 @@ def get_id_token(config=None, expires=None): token = response["id_token"] if config['token_file']: with open(config['token_file'], 'w') as fid: + print(f"Writing token file: {config['token_file']}") fid.write(token) return token diff --git a/.evergreen/auth_oidc/oidc_get_tokens.py b/.evergreen/auth_oidc/oidc_get_tokens.py index d554cf7e..74b00e36 100644 --- a/.evergreen/auth_oidc/oidc_get_tokens.py +++ b/.evergreen/auth_oidc/oidc_get_tokens.py @@ -3,11 +3,11 @@ HERE = os.path.abspath(os.path.dirname(__file__)) sys.path.insert(0, HERE) -from utils import get_secrets, get_id_token, DEFAULT_CLIENT +from utils import get_secrets, get_id_token, DEFAULT_CLIENT, join def main(): - token_dir = os.environ['OIDC_TOKEN_DIR'] + token_dir = os.environ['OIDC_TOKEN_DIR'].replace(os.sep, '/') os.makedirs(token_dir, exist_ok=True) secrets = get_secrets() config = { @@ -18,26 +18,26 @@ def main(): 'client_id': DEFAULT_CLIENT, 'client_secret': secrets['oidc_client_secret'], 'username': 'test_user1', - 'token_file': os.path.join(token_dir, 'test_user1') + 'token_file': join(token_dir, 'test_user1') } get_id_token(config) for i in range(2): - config['token_file'] = os.path.join(token_dir, f'test_user1_{i+1}') + config['token_file'] = join(token_dir, f'test_user1_{i+1}') get_id_token(config) config['issuer'] = secrets['oidc_issuer_2_uri'] config['username'] = 'test_user2' - config['token_file'] = os.path.join(token_dir, 'test_user2') + config['token_file'] = join(token_dir, 'test_user2') get_id_token(config) for i in range(2): - config['token_file'] = os.path.join(token_dir, f'test_user2_{i+1}') + config['token_file'] = join(token_dir, f'test_user2_{i+1}') get_id_token(config) config['issuer'] = secrets['oidc_issuer_1_uri'] config['username'] = 'test_user1' - config['token_file'] = os.path.join(token_dir, 'test_user1_expires') + config['token_file'] = join(token_dir, 'test_user1_expires') get_id_token(config, expires=60) print(f"Wrote tokens to {token_dir}") if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/.evergreen/auth_oidc/oidc_get_tokens.sh b/.evergreen/auth_oidc/oidc_get_tokens.sh index 78c7e978..76fa82a9 100755 --- a/.evergreen/auth_oidc/oidc_get_tokens.sh +++ b/.evergreen/auth_oidc/oidc_get_tokens.sh @@ -1,16 +1,15 @@ #!/usr/bin/env bash # -# Bootstrapping file to launch a local oidc-enabled server and create -# OIDC tokens that can be used for local testing. See README for -# prequisites and usage. +# Get the set of OIDC tokens in the OIDC_TOKEN_DIR. # -set -eux -if [[ -z "${AWS_ROLE_ARN}" || -z "${AWS_ACCESS_KEY_ID}" || -z "${AWS_SECRET_ACCESS_KEY}" ]]; then - echo "Missing AWS credentials" - exit 1 +set -ex +if [ -z "$OIDC_TOKEN_DIR" ]; then + if [ "Windows_NT" = "$OS" ]; then + export OIDC_TOKEN_DIR=C:/Temp/tokens + else + export OIDC_TOKEN_DIR=/tmp/tokens + fi fi -export OIDC_TOKEN_DIR=${OIDC_TOKEN_DIR:-/tmp/tokens} - -rm -rf authoidcvenv +mkdir -p $OIDC_TOKEN_DIR . ./activate-authoidcvenv.sh -python oidc_get_tokens.py \ No newline at end of file +python oidc_get_tokens.py diff --git a/.evergreen/auth_oidc/utils.py b/.evergreen/auth_oidc/utils.py index 27091416..8e62c964 100644 --- a/.evergreen/auth_oidc/utils.py +++ b/.evergreen/auth_oidc/utils.py @@ -5,10 +5,14 @@ import boto3 HERE = os.path.abspath(os.path.dirname(__file__)) -aws_lib = os.path.join(os.path.dirname(HERE), 'auth_aws', 'lib') + +def join(*args): + return os.path.join(*args).replace(os.sep, '/') + +aws_lib = join(os.path.dirname(HERE), 'auth_aws', 'lib') sys.path.insert(0, aws_lib) from aws_handle_oidc_creds import get_id_token, MOCK_ENDPOINT -aws_root = os.path.join(os.path.dirname(HERE), 'auth_aws') +aws_root = join(os.path.dirname(HERE), 'auth_aws') sys.path.insert(0, aws_root) from setup_secrets import get_secrets as root_get_secrets