Users might want to run aws sso login --profile prior
to running kas. Copy config file and sso/cache directory
into $HOME/.aws to allow running Yocto within context of
docs/userguide/aws-sso-warning.inc | 7 +++++++
docs/userguide/credentials.rst | 6 +++++-
docs/userguide/kas-container.rst | 3 +++
kas-container | 2 ++
kas/libcmds.py | 21 +++++++++++++++++++++
5 files changed, 38 insertions(+), 1 deletion(-)
create mode 100644 docs/userguide/aws-sso-warning.inc
diff --git a/docs/userguide/aws-sso-warning.inc b/docs/userguide/aws-sso-warning.inc
new file mode 100644
index 0000000..19bdf71
--- /dev/null
+++ b/docs/userguide/aws-sso-warning.inc
@@ -0,0 +1,7 @@
+.. note::
+ When using |AWS_CONFIG_SOURCE| 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.
+
diff --git a/docs/userguide/credentials.rst b/docs/userguide/credentials.rst
index 94770be..e088e5b 100644
--- a/docs/userguide/credentials.rst
+++ b/docs/userguide/credentials.rst
@@ -23,11 +23,13 @@ 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.
+.. include:: aws-sso-warning.inc
+
Git Configuration
-----------------
@@ -112,3 +114,5 @@ by setting ``SSH_PRIVATE_KEY`` or ``SSH_PRIVATE_KEY_FILE``.
.. note::
The use of an external ssh agent cannot be combined with options that
require an internal ssh agent.
+
+.. |AWS_CONFIG_SOURCE| replace:: ``AWS_CONFIG_FILE``
diff --git a/docs/userguide/kas-container.rst b/docs/userguide/kas-container.rst
index 0ace45a..4acabe7 100644
--- a/docs/userguide/kas-container.rst
+++ b/docs/userguide/kas-container.rst
@@ -7,6 +7,9 @@ Building in a Container
.. include:: ../_build/kas-container-usage-options.inc
+.. include:: aws-sso-warning.inc
+
.. |SYNOPSIS| replace:: Synopsis
.. |OPTIONS| replace:: Options
.. |KAS-COMMANDS| replace:: kas-container Commands
+.. |AWS_CONFIG_SOURCE| replace:: ``--aws-dir ~/.aws``
diff --git a/kas-container b/kas-container
index 6000783..f830312 100755
--- a/kas-container
+++ b/kas-container
@@ -80,6 +80,8 @@ usage()
"container.\n"
printf "%b" "--ssh-agent\t\tForward ssh-agent socket to the container.\n"
printf "%b" "--aws-dir\t\tDirectory containing AWScli configuration.\n"
+ printf "%b" "\t\t\tAvoid \$HOME/.aws unless you fully trust the " \
+ "container.\n"
printf "%b" "--git-credential-store\tFile path to the git credential " \
"store\n"
printf "%b" "--no-proxy-from-env\tDo not inherit proxy settings from " \
diff --git a/kas/libcmds.py b/kas/libcmds.py
index 6dbffd2..05f0871 100644
--- a/kas/libcmds.py
+++ b/kas/libcmds.py
@@ -274,6 +274,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 = \
@@ -298,6 +299,26 @@ class SetupHome(Command):
config.write(fds)
shutil.copy(aws_web_identity_token_file, webid_token_file)
+ # SSO workflow
+ 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")
+
+ # In kas-container the directory passed in --aws-dir is not
+ # mounted in $HOME. Look for sso/cache in directory containing
+ # AWS_CONFIG_FILE first to maintain the same behavior between
+ # kas and kas-container.
+ aws_cache_dir = None
+ if os.path.isdir(aws_cache_dir_conf):
+ aws_cache_dir = aws_cache_dir_conf
+ elif os.path.isdir(aws_cache_dir_home):
+ aws_cache_dir = aws_cache_dir_home
+
+ if aws_cache_dir:
+ shutil.copy(aws_conf_file, conf_file)
+ shutil.copytree(aws_cache_dir, sso_cache_dir)
+
@staticmethod
def _setup_gitlab_ci_ssh_rewrite(config):
ci_host = os.environ.get('CI_SERVER_HOST', None)
--
2.47.1