-
Notifications
You must be signed in to change notification settings - Fork 1
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 secrets config and vault secret actions #22
Conversation
20cacf7
to
24634f3
Compare
24634f3
to
cbb502a
Compare
431eb11
to
fed3761
Compare
f64f502
to
1fed64f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! This is really nice, some non-blocking suggestions and one important question around the use of temporal actions to add and remove vault secrets.
charm.framework.observe(charm.on.get_vault_secret_action, self._on_get_vault_secret) | ||
|
||
@log_event_handler(logger) | ||
def _on_add_vault_secret(self, event): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: I'm a bit confused as to why we would add secrets to vault via Temporal - is there no way to do this directly on vault? Seems to me this should be Vault not Temporal functionality. I thought there might be some separation of access such that whoever has access to the worker charm didn't necessarily have access to vault to change credentials - this seems to go against that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a case of separation of access v practicality. We had a similar discussion for the Temporal charm when adding the OpenFGA relation in this PR, where we added utility actions for interacting with the OpenFGA store through the Temporal charm.
There is a way of doing it directly through the vault snap, but not through actions on the Vault charm. I opted to go down a similar path as the Temporal charm and add some utility methods that allow users to easily add secrets to Vault through the Temporal worker charm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is required at the moment to make the charm functional, ok, but i agree with Amber that this defies a bit the point of Valut. If the same party can read and write secrets in/from Vault, there is practically no difference between using vault or an environment variable. If we have a centralized vault, we'd assume that different people add secrets potentially via the UI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some small comments but none of them is a blocker. Great work!
6034ab5
to
c36333e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments, nothing blocking.
README.md
Outdated
##### **`secrets.yaml`** | ||
|
||
```yaml | ||
secrets: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if we called it environment.yaml (since not all envs are secrets, but all secrets are envs)
what if we put env as root:
env:
plain (or default):
- key1: value1
juju:
...
vault:
...
or a more k8s-ish syntax
env:
- name: key1
value: val1
- name: key2
valueFromSecret:
type: juju
id: secret-id
key: key2
- name: key3
valueFromSecret:
type: vault
id: secret-path
key: key3
or a more compact form of this:
env:
- name: key1
value: val1
- name: key2
valueFromSecret: juju@secret-id:key2
- name: key3
valueFromSecret: vault@secret-path:key3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I went with the low impact change, as I'd like to avoid having the config look k8s-ish, and the compact form might have readability issues.
secrets: | ||
juju: | ||
- secret-id: <secret_id> | ||
key: key1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: the key here matches both the key in the secret and the name of the environment variable right? I think there might be cases when that could be annoying because as a developer you are obliged to use an env that you might not know from the beginning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand but yes the key in the secret must match the key that the user specified in their code. What would be an alternative?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a bit related to the convo Amber touched on. People who set secrets should in general be different from the ones who write the code. So in the code you know you need some environment variable, but you should be able to call it whatever you want (say MY_ENV
). Similarly, the person who writes the secret, can put a whatever key (say my_secret
). Only at the moment of the deployment, you should say: load my_secret
value into MY_ENV
. We should not assume that the programmer knows that the key is my_secret
and do os.getenv('my_secret')
from the beginning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. So for juju and Vault, I guess we will need to add an optional key of what the env variable name should be? Something like:
juju:
- secret-id: <secret_id>
src-key: key
dest-key: MY_ENV
Or it could be (I like this more):
juju:
- secret-id: <secret_id>
key-name: MY_ENV
from-key: key
Any suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is fine, but then i think you would need to keep the env consistent:
env:
- name: MY_ENV1
value: bla bla
juju:
- name: MY_ENV2
secret-id: secret-id
key: key2
vault:
- name: MY_ENV3
secret-path: secret-path
key: key3
charm.framework.observe(charm.on.get_vault_secret_action, self._on_get_vault_secret) | ||
|
||
@log_event_handler(logger) | ||
def _on_add_vault_secret(self, event): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is required at the moment to make the charm functional, ok, but i agree with Amber that this defies a bit the point of Valut. If the same party can read and write secrets in/from Vault, there is practically no difference between using vault or an environment variable. If we have a centralized vault, we'd assume that different people add secrets potentially via the UI.
65e9238
to
e8dce0b
Compare
b37072c
to
2812d5b
Compare
This PR introduces the following changes and additions:
env-file
resource to specify a set of environment variables which should be injected into the workload container and used by the workflow definitions. This approach was problematic in that it handles secret credentials poorly. Theenv-file
is now deprecated in favor of thesecrets
config described below.secrets
config parameter, which can be used to instruct the charm to fetch secrets from three sources and inject them as environment variables into the workload container:env
: These are plaintext environment variables, which are usually not secret.juju
(Requires Juju 3.3+): These are variables stored as Juju secrets, where the user provides the ID of the secret and the key from which to fetch the value.vault
: These are variables fetched from Vault, provided the charm is related to a Vault charm.Thanks to @gtato for the suggestions and useful design discussions.