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

CSS-8226 Vault k8s relation #1197

Merged
merged 5 commits into from
Apr 26, 2024

Conversation

alesstimec
Copy link
Collaborator

Description

  • switches to the new vault relation interface used by the vault-k8s charm
  • switches vault auth to role_id, role_secret_id

Note: did not change the VM charm. also means we won't be able to relate to the vault VM charm.

Engineering checklist

Check only items that apply

  • Documentation updated
  • Covered by unit tests
  • Covered by integration tests

Test instructions

Notes for code reviewers

harness.set_leader(True)
harness.begin_with_initial_hooks()
self.harness.enable_hooks()
self.harness.charm._on_install(None)
Copy link
Member

Choose a reason for hiding this comment

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

It's a bit cleaner if we could use self.harness.charm.on.install.emit().

Copy link
Contributor

@ale8k ale8k left a comment

Choose a reason for hiding this comment

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

lgtm minor comments

charms/jimm-k8s/requirements.txt Show resolved Hide resolved
charms/jimm-k8s/src/charm.py Show resolved Hide resolved
charms/jimm-k8s/src/charm.py Outdated Show resolved Hide resolved
@@ -191,15 +191,15 @@ func TestAddController(t *testing.T) {
func TestAddControllerWithVault(t *testing.T) {
c := qt.New(t)

client, path, creds, ok := jimmtest.VaultClient(c, "../../")
client, path, roleID, roleSecretID, ok := jimmtest.VaultClient(c, "../../")
Copy link
Contributor

Choose a reason for hiding this comment

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

Much prefer this

internal/vault/vault.go Outdated Show resolved Hide resolved
if err != nil {
return nil, errors.E(op, err, "unable to login to approle auth method")
}
if authInfo == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this even happen??

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

copied from the vault reference example, so i assume it can happen

// be made to use a vault server and JIMM will store everything in
// it's local database.
VaultSecretFile string
VaultRoleID string
Copy link
Contributor

Choose a reason for hiding this comment

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

We called it RoleId and RoleSecretId earlier, can we make them consistent? Perhaps AppRoleId and AppRoleSecretId in both areas?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also godoc

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

service params deal with many aspects of JIMM.. i much prefer that the field name specifically mentions which bit it is intended for..

Copy link
Contributor

@kian99 kian99 left a comment

Choose a reason for hiding this comment

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

Some comments, we will also need to fix our Docker Compose, that is why the smoke test is failing.

charms/jimm-k8s/requirements.txt Outdated Show resolved Hide resolved
charms/jimm-k8s/src/charm.py Outdated Show resolved Hide resolved
Comment on lines 318 to 319
if vault_config:
config_values.update(vault_config)
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we should check if vault_config is None then enter a blocked state. You might also want to check whether the config for insecure_secret_storage is set to true to allow JIMM to start without vault provided that config value is set.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done, i think

Comment on lines +411 to +415
# update vault relation if exists
binding = self.model.get_binding("vault-kv")
if binding is not None:
egress_subnet = str(binding.network.interfaces[0].subnet)
self.interface.request_credentials(event.relation, egress_subnet, self.get_vault_nonce())
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it intentional to put this in the update-status hook? Considering that the hook runs every 5m by default. Couldn't we put the self.interface.request_credentials somewhere that is only triggered when the relation to Vault is made.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes... that's what the library suggests.

def _on_vault_connected(self, event: vault_kv.VaultKvConnectedEvent):
relation = self.model.get_relation(event.relation_name, event.relation_id)
egress_subnet = str(self.model.get_binding(relation).network.interfaces[0].subnet)
self.vault.request_credentials(relation, egress_subnet, self.get_vault_nonce())
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah we are doing it here as well? But here we are doing self.vault.requests_credentials rather than self.interface.request_credentials above, I imagine one might be wrong?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

both are suggested by the lib

charms/jimm-k8s/src/charm.py Outdated Show resolved Hide resolved
@alesstimec alesstimec force-pushed the vault-k8s-relation branch 7 times, most recently from 2a6977e to 22339e4 Compare April 25, 2024 14:59
- switches to the new vault relation interface used by the vault-k8s charm
- switches vault auth to role_id, role_secret_id

Note: did not change the VM charm. also means we won't be able to relate
to the vault VM charm.
alesstimec and others added 4 commits April 25, 2024 18:00
- Also updated the ingress relation to the latest and it seems v1 of the relation interface is deprecated, we should move to v2 in a separate PR.
@kian99 kian99 merged commit b3aeb5f into canonical:feature-oidc Apr 26, 2024
10 checks passed
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.

4 participants