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 resource_secret and resource_access_secret #454

Merged
merged 1 commit into from
Apr 22, 2024

Conversation

anvial
Copy link
Member

@anvial anvial commented Apr 16, 2024

Description

This PR introduces the ability to manage secret access in the Juju provider.
It includes the creation, reading, updating, and deletion of secret access.
The changes also handle the granting and revoking of secret access to applications.
Additionally, it includes the necessary error handling and diagnostics for these operations.

Fixes:

Type of change

  • Add new resource

Environment

  • Juju controller version:

  • Terraform version:

QA steps

terraform {
  required_providers {
    juju = {
      source  = "juju/juju"
      version = "0.11.0"
    }
  }
}
provider "juju" {}

resource "juju_model" "my_model" {
   name = "tf-secret-test"
}

resource "juju_secret" "my_secret" {
  model = juju_model.my_model.name
  name  = "my_secret_name"
  value = {
    key1 = "value1"
    key2 = "value2"
  }
  info  = "This is my secret"
}

resource "juju_application" "jul" {
  name  = "jul"
  model = juju_model.my_model.name

  charm {
    name     = "jameinel-ubuntu-lite"
    channel  = "latest/stable"
  }

  units = 1
}

resource "juju_application" "jul2" {
  name  = "jul2"
  model = juju_model.my_model.name

  charm {
    name     = "jameinel-ubuntu-lite"
    channel  = "latest/stable"
  }

  units = 1
}

resource "juju_access_secret"  "my_access_secret" {
  model = juju_model.my_model.name
  applications = [
    juju_application.jul.name, juju_application.jul2.name
  ]
  secret_id = juju_secret.my_secret.secret_id
}

After check that secrets created and granted:

juju switch tf-secret-test
juju show-secret my_secret

Change the list of apps in plan and check secret info again.

Additional notes

JUJU-5711

@anvial anvial added this to the 0.12.0 milestone Apr 16, 2024
@anvial anvial changed the title Add resource secret access [WIP] Add resource secret access Apr 16, 2024
Copy link
Contributor

@cderici cderici left a comment

Choose a reason for hiding this comment

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

Awesome addition! I see a bunch of spots where things were already reviewed and fixed (e.g., #451), so a rebase is needed to iron out those. QA steps needed.

Needs a final review and QA after those and the current comments are addressed 👍

internal/provider/resource_secret_access.go Outdated Show resolved Hide resolved
internal/juju/secrets.go Outdated Show resolved Hide resolved
internal/provider/resource_secret_access.go Outdated Show resolved Hide resolved
internal/provider/resource_secret_access.go Outdated Show resolved Hide resolved
internal/provider/resource_secret_access.go Outdated Show resolved Hide resolved
internal/provider/resource_secret_access.go Outdated Show resolved Hide resolved
internal/provider/resource_secret_access.go Outdated Show resolved Hide resolved
internal/provider/resource_secret_access.go Outdated Show resolved Hide resolved
internal/provider/resource_secret_access.go Outdated Show resolved Hide resolved
internal/provider/resource_secret_access.go Outdated Show resolved Hide resolved
@anvial anvial force-pushed the add-resource-secret-access branch 8 times, most recently from ae0f045 to d8d3763 Compare April 18, 2024 18:58
@anvial anvial requested a review from hmlanigan April 18, 2024 19:27
@anvial anvial changed the title [WIP] Add resource secret access Add resource secret access Apr 18, 2024
@anvial anvial force-pushed the add-resource-secret-access branch 4 times, most recently from e9466db to ac50a66 Compare April 18, 2024 19:41
Copy link
Member

@hmlanigan hmlanigan left a comment

Choose a reason for hiding this comment

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

Apologies for noticing this late. We should name this new resource access_secret to be consistent with access_model.

You need the example.tf and import.sh files for the documents to create the new docs/resources/access_model.md

internal/juju/secrets.go Outdated Show resolved Hide resolved
internal/provider/resource_secret_access.go Outdated Show resolved Hide resolved
internal/provider/resource_secret_access.go Outdated Show resolved Hide resolved
internal/provider/resource_secret_access.go Outdated Show resolved Hide resolved
internal/provider/resource_secret_access.go Outdated Show resolved Hide resolved
internal/provider/resource_secret_access_test.go Outdated Show resolved Hide resolved
internal/provider/resource_secret_access_test.go Outdated Show resolved Hide resolved
internal/provider/resource_secret_access_test.go Outdated Show resolved Hide resolved
internal/juju/secrets.go Outdated Show resolved Hide resolved
internal/juju/secrets.go Outdated Show resolved Hide resolved
@anvial anvial force-pushed the add-resource-secret-access branch 3 times, most recently from ac2b124 to 2769399 Compare April 19, 2024 08:57
@anvial anvial requested a review from hmlanigan April 19, 2024 08:57
@anvial anvial changed the title Add resource secret access Add resource_access_secret Apr 19, 2024
templates/index.md.tmpl Outdated Show resolved Hide resolved
go.mod Outdated
@@ -22,6 +22,7 @@ require (
github.com/juju/cmd/v3 v3.0.14
github.com/juju/collections v1.0.4
github.com/juju/errors v1.0.0
github.com/juju/names/v4 v4.0.0
Copy link
Member

Choose a reason for hiding this comment

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

Why do we have direct use of names/v4 again? This was removed in a PR which landed yesterday.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that we did not get rid of it completely. It looks like it is used in application_test.go resource_model.go still.

docs/index.md Outdated Show resolved Hide resolved
internal/juju/applications_test.go Show resolved Hide resolved
@hmlanigan hmlanigan dismissed cderici’s stale review April 19, 2024 18:08

Caner is out an unable to re-review - I've taken over reviewing the changes.

@hmlanigan
Copy link
Member

I'll fix Import for both resources in a follow on PR shortly

@hmlanigan hmlanigan changed the title Add resource_access_secret Add resource_secret and resource_access_secret Apr 19, 2024
@hmlanigan
Copy link
Member

@anvial you need to rebase and resolve the conflict. This will also pick up the GitHub action updates from @Aflynn50 to add the test env var.

Copy link
Member

@hmlanigan hmlanigan left a comment

Choose a reason for hiding this comment

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

LGTM - just need to rebase.

@anvial anvial force-pushed the add-resource-secret-access branch from e1a2041 to c85c1bf Compare April 22, 2024 07:05
This commit introduces internal/juju/userSecret and adds method to add user secrets.

Implement internal Juju secrets add, update, and remove functionality

This commit introduces several changes to the Juju client in the `internal/juju/client.go` file.
It includes the implementation of methods for adding, updating, and removing secrets. Additionally,

Furthermore, the commit includes changes to the `secret.go` file, introducing new types for managinng secrets.
It also includes changes to the `interfaces.go` file, defining new interfaces for the Juju client API.

Add secretURI to UpdateSecret

Add secretURI to DeleteSecret

Add AutoPrunt to UpdateSecret schema

Add SecretId to ReadSecret func instead of name.

Add lost Asserts.

Add secretNotFoundError

Extract mocks creation into separate suite.

Introduce typedError(err) usage in ClientAPI funcs.

Add renaming to UpdateSecret

Use struct raather than pointer for Output structures.

Introcue NewName in Update input struct.

Use pointers in all places in structs where the parameter is not
neccessary.

Implement schema for user secrets management

This commit introduces the ability to add, update, and remove user secrets in the schema.
This is done through the `userSecretResource` struct, which has methods for each of these actions.
The `Add`, `Update`, and `Remove` methods are currently stubbed out and will need to be implemented in future commits.

Add ReadSecret function implementation.

Implement Delete secret function

Add base64 encoding co Create and change Read fucntion to get value with
decode.

Add base64 encoding for values in Update
@anvial anvial force-pushed the add-resource-secret-access branch from c85c1bf to d41084a Compare April 22, 2024 07:06
@anvial anvial merged commit 6c744a8 into juju:main Apr 22, 2024
25 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.

3 participants