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

implement secret handling for workspace_service_account table #11946

Conversation

subodh1810
Copy link
Contributor

@subodh1810 subodh1810 commented Apr 12, 2022

Issue : #11968

@subodh1810 subodh1810 self-assigned this Apr 12, 2022
@subodh1810 subodh1810 temporarily deployed to more-secrets April 13, 2022 06:36 Inactive
@subodh1810 subodh1810 temporarily deployed to more-secrets April 13, 2022 06:36 Inactive
@subodh1810 subodh1810 temporarily deployed to more-secrets April 13, 2022 07:13 Inactive
@subodh1810 subodh1810 temporarily deployed to more-secrets April 13, 2022 07:13 Inactive
@subodh1810 subodh1810 marked this pull request as ready for review April 13, 2022 13:26
private static TextNode getOrThrowSecretValueNode(final ReadOnlySecretPersistence secretPersistence, final SecretCoordinate coordinate) {
private static JsonNode getOrThrowSecretValueNode(final ReadOnlySecretPersistence secretPersistence,
final SecretCoordinate coordinate,
final boolean asTextNode) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick. Whether the secret value is a text or json depends on the type of the secret. The asTextNode parameter makes it sound like the client can choose between the two types at will, which is slightly misleading. Maybe rename it to something like isTextSecret?

Since there are only two use cases of this method, this is probably over-optimization. So feel free to ignore.

Copy link
Contributor

Choose a reason for hiding this comment

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

would it make sense to just have an inner and outter method here and get rid of the boolean? i think it would be a lot clearer what's happening.

JsonNode getOrThrowSecretValueJsonNode(...) {
 ...
} 
TextNode   getOrThrowSecretValueTextNode(...) {
  return getOrThrowSecretValueJsonNode(...).asTextNode();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively, getOrThrowSecretValueNode is called two times, once to get the text node, and once to get the json node. So this helper method is not that useful. It's also fine to just remove it.

final SecretsRepositoryReader secretsRepositoryReader =
spy(new SecretsRepositoryReader(configRepository, realSecretsHydrator));

final UUID workspaceId = UUID.fromString("13fb9a84-6bfa-4801-8f5e-ce717677babf");
Copy link
Contributor

Choose a reason for hiding this comment

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

Many of the UUIDs and constants are reused in the two test files, like this workspace ID, the service account ID, and HMAC key. They can be moved to MockData.java for clarity.

Copy link
Contributor

@cgardens cgardens left a comment

Choose a reason for hiding this comment

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

i think the approach makes sense! nice work.

mostly comments on clarity. i want to be really picky about that here since secrets are involved.

private static TextNode getOrThrowSecretValueNode(final ReadOnlySecretPersistence secretPersistence, final SecretCoordinate coordinate) {
private static JsonNode getOrThrowSecretValueNode(final ReadOnlySecretPersistence secretPersistence,
final SecretCoordinate coordinate,
final boolean asTextNode) {
Copy link
Contributor

Choose a reason for hiding this comment

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

would it make sense to just have an inner and outter method here and get rid of the boolean? i think it would be a lot clearer what's happening.

JsonNode getOrThrowSecretValueJsonNode(...) {
 ...
} 
TextNode   getOrThrowSecretValueTextNode(...) {
  return getOrThrowSecretValueJsonNode(...).asTextNode();
}

clonedWorkspaceServiceAccount.setJsonCredential(jsonCredSecretCoordinateToPayload.secretCoordinateForDB());
}

if (workspaceServiceAccount.getHmacKey() != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

i'm lost here. i understood lines 277-191 are storing a service account. from here down i'm not quite sure what this key is. i think we need the code to explain that somewhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks. is all of this specific to a GCP service account (as opposed to an AWS one?)? If they are different how will we tell in the future? As long as we have answer to this, then all good. If it GCP specific now, worth adding a comment mentioning that as well and that we plan for it to evolve.

@subodh1810 subodh1810 temporarily deployed to more-secrets April 25, 2022 21:58 Inactive
@subodh1810 subodh1810 temporarily deployed to more-secrets April 25, 2022 21:58 Inactive
Copy link
Contributor

@cgardens cgardens left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM.

*/
private static TextNode getOrThrowSecretValueNode(final ReadOnlySecretPersistence secretPersistence, final SecretCoordinate coordinate) {
private static String getOrThrowSecretValueNode(final ReadOnlySecretPersistence secretPersistence,
Copy link
Contributor

Choose a reason for hiding this comment

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

getOrThrowSecretValueNode => getOrThrowSecretValue or even getOrThrowSecret. It's not a "node" anymore, right?

clonedWorkspaceServiceAccount.setJsonCredential(jsonCredSecretCoordinateToPayload.secretCoordinateForDB());
}

if (workspaceServiceAccount.getHmacKey() != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks. is all of this specific to a GCP service account (as opposed to an AWS one?)? If they are different how will we tell in the future? As long as we have answer to this, then all good. If it GCP specific now, worth adding a comment mentioning that as well and that we plan for it to evolve.

@subodh1810 subodh1810 temporarily deployed to more-secrets April 26, 2022 13:06 Inactive
@subodh1810 subodh1810 temporarily deployed to more-secrets April 26, 2022 13:06 Inactive
@subodh1810 subodh1810 merged commit c4d1837 into introduce-persistence-code-for-service-account-table Apr 26, 2022
@subodh1810 subodh1810 deleted the secret-management-for-service-account-creds branch April 26, 2022 13:48
subodh1810 added a commit that referenced this pull request Apr 26, 2022
* implement persistence code for workspace_service_account table

* update yaml

* implement secret handling for workspace_service_account table (#11946)

* implement secret handling for workspace_service_account table

* add new line to the mock json

* get rid of file

* address review comments

* update method name and add comment
subodh1810 added a commit that referenced this pull request Apr 26, 2022
* implement migration to create workspace_service_account table

* make all columns non nullable

* introduce persistence code for service account table (#11944)

* implement persistence code for workspace_service_account table

* update yaml

* implement secret handling for workspace_service_account table (#11946)

* implement secret handling for workspace_service_account table

* add new line to the mock json

* get rid of file

* address review comments

* update method name and add comment
suhomud pushed a commit that referenced this pull request May 23, 2022
* implement migration to create workspace_service_account table

* make all columns non nullable

* introduce persistence code for service account table (#11944)

* implement persistence code for workspace_service_account table

* update yaml

* implement secret handling for workspace_service_account table (#11946)

* implement secret handling for workspace_service_account table

* add new line to the mock json

* get rid of file

* address review comments

* update method name and add 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.

4 participants