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

Add config options for access-key, secret-key #76

Closed
wants to merge 7 commits into from

Conversation

sed-i
Copy link

@sed-i sed-i commented Nov 16, 2024

Problem

For COS we're now using s3-integrator in all deployments.
With terraform, running actions on a deployment is a bit involved.

Solution

Add config options for access-key, secret-key.
Since the secrets are already stored in reldata, not much additional harm having them also in the config.
Fixes #62.

Side-effect

Since we can now have credentials from two sources (action, config), the new logic introduced in this PR has a new side effect: even when the config options are cleared via

juju config s3i access-key= secret-key=
# or
juju config s3i --reset access-key,secret-key

the credentials still stay in app data. To clear app data after config values were cleared, we'd need to follow-up with the action,

juju run s3i/0 sync-s3-credentials access-key= secret-key=

@sed-i sed-i changed the title Feature/cli secret Add config options for access-key, secret-key Nov 16, 2024
@sed-i sed-i marked this pull request as ready for review November 16, 2024 04:58
Copy link

@phvalguima phvalguima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sed-i, def. an improvement we need to do. What I would recommend instead is to use Juju's user-secret feature. We have another example already doing so. It is also compliant with terraform, as juju provider allows to create secrets as resources.

We have a very similar pattern for object-storage-integrator, which is used with azure, here. I recommend:

  • remove the access-key and secret-key configs and create one config named credentials
  • pass credentials as a type secret.

Also, can you update README and the config description to explain how to use juju add-secret, as described here.

Access Key (account) for connecting to the object storage.
This config option takes precedence over values passed via the sync-s3-credentials action.
This value must be unset for the action to have effect.
secret-key:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are handling secrets, then we should use user secrets here. One example

secret-key:
type: string
description: |
Access Key Secret (password) for connecting to the object storage.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Access Key Secret (password) for connecting to the object storage.
Create a secret in juju with: `juju add-secret ...`
Pass the secret ID as this config option instead.

# We sync credentials only if one of the config options is given, because we do
# not want to accidentally wipe credentials previously set by the sync action.
access_key = self.config.get("access-key")
secret_key = self.config.get("secret-key")
Copy link

@phvalguima phvalguima Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
secret_key = self.config.get("secret-key")
try:
secret_credentials_id = self.config.get("credentials")
access_key = model.get_secret(id=secret_credentials_id).get_content(refresh=True).get("access-key")
secret_key = model.get_secret(id=secret_credentials_id).get_content(refresh=True).get("secret-key")
except ...:

As shown here

if access_key or secret_key:
# This will be called twice, but it's ok because ops buffers relation writes.
self._sync_s3_credentials(
self.config.get("access-key"), self.config.get("secret-key")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above, replace it for the secret contents instead.

@delgod
Copy link
Member

delgod commented Nov 18, 2024

Hi Leon,

It is an intentional design choice not to have access and secret keys as config values because this approach is not secure.
Please contact Jon if you have any concerns about insecure config options.

On the other hand, we cannot move to user secrets yet because we need to support Juju 2.9 deployments.
Our intent is to eventually add s3 interface support to object-storage-integrator and use it on Juju 3+ deployments.

@delgod delgod closed this Nov 18, 2024
@sed-i
Copy link
Author

sed-i commented Nov 22, 2024

Hi @delgod,
Not sure what you mean.
Yes, secrets as config options are not great, but this charm is already leaking same secrets over peer relation.
I.e., afaiu, the secrets are cleartext via juju show-unit already.

@hloeung
Copy link

hloeung commented Jan 9, 2025

Can we reconsider this per @sed-i's comment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: access-key and secret-key as Juju Config instead of action
4 participants