Users might want to run aws sso login --profile prior
to running kas, this change copies config file and .aws/sso/cache
directory to allow running Yocto within context of AWS session.
Signed-off-by: Łukasz Płachno <
lukasz....@verkada.com>
---
docs/userguide/credentials.rst | 9 ++++++++-
kas/libcmds.py | 16 ++++++++++++++++
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/docs/userguide/credentials.rst b/docs/userguide/credentials.rst
index 94770be..8cf6aaa 100644
--- a/docs/userguide/credentials.rst
+++ b/docs/userguide/credentials.rst
@@ -23,11 +23,18 @@ into the isolated environment first.
AWS Configuration
-----------------
-For AWS, both conventional AWS config files as well as the environment
+For AWS, conventional AWS config files, AWS SSO as well as the environment
variable controlled OAuth 2.0 workflow are supported. Note, that KAS
internally rewrites the ``AWS_*`` environment variables into a AWS
config file to also support older versions of bitbake.
+.. note::
+ When using AWS SSO credentials the entire content of ~/.aws/sso/cache
+ directory is copied into the kas workspace. This might expose all active
+ user sessions, including those not defined in the ``AWS_CONFIG_FILE``.
+ To mitigate security risks, log out of unnecessary profiles before
+ starting a build or use a separate system account to run the build.
+
Git Configuration
-----------------
diff --git a/kas/libcmds.py b/kas/libcmds.py
index bf02fce..4da1644 100644
--- a/kas/libcmds.py
+++ b/kas/libcmds.py
@@ -273,6 +273,7 @@ class SetupHome(Command):
aws_dir = self.tmpdirname + "/.aws"
conf_file = aws_dir + "/config"
shared_creds_file = aws_dir + "/credentials"
+ sso_cache_dir = aws_dir + "/sso/cache"
os.makedirs(aws_dir)
aws_conf_file = self._path_from_env('AWS_CONFIG_FILE')
aws_shared_creds_file = \
@@ -297,6 +298,21 @@ class SetupHome(Command):
config.write(fds)
shutil.copy(aws_web_identity_token_file, webid_token_file)
+ # SSO workflow
+ # when using kas-container ~/.aws is mounted in /var/kas/userdata/.aws,
+ # within container ~/.aws/sso/cache will not exist.
+ if aws_conf_file:
+ aws_cache_dir_conf = \
+ os.path.join(os.path.dirname(aws_conf_file), "sso/cache")
+ aws_cache_dir_home = os.path.join(Path.home(), ".aws/sso/cache")
+
+ if os.path.isdir(aws_cache_dir_conf):
+ shutil.copy(aws_conf_file, conf_file)
+ shutil.copytree(aws_cache_dir_conf, sso_cache_dir)
+ elif os.path.isdir(aws_cache_dir_home):
+ shutil.copy(aws_conf_file, conf_file)
+ shutil.copytree(aws_cache_dir_home, sso_cache_dir)
+
@staticmethod
def _setup_gitlab_ci_ssh_rewrite(config):
ci_host = os.environ.get('CI_SERVER_HOST', None)
--
2.47.1