Skip to content

Conversation

dragomirp
Copy link
Contributor

@dragomirp dragomirp commented Aug 12, 2025

Implement a way to request entity name by passing a secret.

Draft implementation PRs:

@dragomirp dragomirp force-pushed the dpe-7379-user-creation branch 4 times, most recently from 31f17de to b75d73d Compare August 12, 2025 18:32
@dragomirp dragomirp force-pushed the dpe-7379-user-creation branch from b75d73d to 69b2e2d Compare August 12, 2025 18:48
@@ -1 +1 @@
ops >= 2.0.0
ops >= 2.0.0, < 3.0.0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ops 3 doesn't doesn't work on focal.

@@ -1926,13 +1926,27 @@ def __init__(
extra_group_roles: Optional[str] = None,
entity_type: Optional[str] = None,
entity_permissions: Optional[str] = None,
requested_entity_secret: Optional[str] = None,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pass a secret URI directly. Simpler but the user needs to manage grants and clean up the secret after relation.

Comment on lines +1930 to +1931
requested_entity_name: Optional[str] = None,
requested_entity_password: Optional[str] = None,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pass the entity name and a password, to create a temporary secret from inside the lib.

):
try:
secret = self.framework.model.get_secret(id=secret_uri)
secret.remove_all_revisions()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't remove the relation data, so that the secret isn't recreated.

@dragomirp dragomirp added the enhancement New feature or request label Aug 12, 2025
@dragomirp dragomirp marked this pull request as ready for review August 12, 2025 21:08
Copy link

@Gu1nness Gu1nness left a comment

Choose a reason for hiding this comment

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

Excellent work overall, just a very few questions.
Could you add some unit tests to the PR on top of the integration testing so that we can ensure easily the safeguards you added (not mixing the secret uri and requested username + password) ?

) and not self.secrets_enabled:
raise SecretsUnavailableError("Secrets unavailable on current Juju version")

if self.requested_entity_secret and self.requested_entity_name:

Choose a reason for hiding this comment

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

Also add the case where requested_entity_secret and requested_entity_password to prevent that case as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checks for entity secret and entity password conflict and for entity password without entity name added in 09f95f2

# Create helper secret if needed
if (
self.relation_data.requested_entity_name
and "requested-entity-secret" not in event_data

Choose a reason for hiding this comment

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

For consistency of checks I would rather use and not self.relation_data.requested_entity_secrets.
Or there's a difference semantically in this case ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in fc5f510. My concern was if the secret will be recreated, but it doesn't seem to happen when scaling data-int on k8s.

Comment on lines 3557 to 3559
self.relation_data.requested_entity_name: str(
self.relation_data.requested_entity_password
)

Choose a reason for hiding this comment

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

I'm not sure I'm fully happy about the formatting here.
If I understand correctly, this means the format is <username>: <password | None > ?
What about this other option ?

username: <username>
password: <password>

I'm just a bit afraid of the None encoded as a string in this case whereas the other way we could just not add the password field ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My concern here is v1 compatibility, my understanding is that we should be able to set multiple entities in v1 which should be easier with a mapping (one key, one entity). With explicit name and password we have to decide how to expand on this. Multiple secrets would be too much complexity IMHO, so we'll most probably need to somehow serialise the name/pass pairs, either by setting lists of names and passwords matching by index, eg:

names: ["username1", "rolename1", "username2"]
passwords: ["pass1" null, null]

Possibly passing the type here as well (type: ["user", "role", "user"]).

Or having a nested mapping inside the predefined secret key, eg:

requested-entities: {"username1": { "password": "pass1", "type": "user"}, "rolename1" {"password": null, "type": "role"}}

Since this is still a WIP, I'm not opposed to changing the format, so the question is which would be the most appropriate way to make this v1 compatible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rechecked the specification and the agreed format is:

entity-name: <username>
password: <password>

Updated to that format in 3f7d614.

self.relation_data.requested_entity_password
)
},
label=f"{self.model.uuid}-{event.relation.id}-requested-entity",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switched to globally unique label.

Copy link
Member

@marceloneppel marceloneppel left a comment

Choose a reason for hiding this comment

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

LGTM

@dragomirp
Copy link
Contributor Author

Charm interfaces PR: canonical/charm-relation-interfaces#294

@dragomirp
Copy link
Contributor Author

Had to pin ops dependency for the s3 test charm as well.

@dragomirp dragomirp merged commit 3c4f5d4 into main Aug 28, 2025
63 of 64 checks passed
@dragomirp dragomirp deleted the dpe-7379-user-creation branch August 28, 2025 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants