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

Refresh on Deployment Settings always shows a diff if there are secrets #123

Closed
komalali opened this issue Apr 7, 2023 · 5 comments
Closed
Assignees
Labels
bug-bash-candidate customer/feedback Feedback from customers kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Milestone

Comments

@komalali
Copy link
Member

komalali commented Apr 7, 2023

The underlying deployment settings API does not return any secret values on GET. As a result, on refresh, there is always a diff as the secret values are replaced by the string secret. Subsequently, an update also shows a diff.

To work through this, we will likely need to implement an endpoint for deployment settings that returns the secret values.

@komalali komalali added the kind/bug Some behavior is incorrect or out of spec label Apr 7, 2023
@cleverguy25 cleverguy25 added this to the 0.102 milestone Feb 16, 2024
@cleverguy25 cleverguy25 removed this from the 0.102 milestone Apr 24, 2024
@IaroslavTitov IaroslavTitov self-assigned this Apr 24, 2024
@IaroslavTitov
Copy link
Contributor

Investigating into this using this example resource:

var settings = new DeploymentSettings(
        "My Settings",
        new DeploymentSettingsArgs{
            Organization = "IaroslavTitov",
            Project = "PulumiDotnet",
            Stack = "SdkTest4",
            SourceContext = new DeploymentSettingsSourceContextArgs{
                Git = new DeploymentSettingsGitSourceArgs{
                    RepoUrl = "https://fake-test.com",
                    Branch = "test",
                    GitAuth = new DeploymentSettingsGitSourceGitAuthArgs {
                        BasicAuth = new DeploymentSettingsGitAuthBasicAuthArgs{
                            Username = "IaroTest",
                            Password = "IaroTest"
                        }
                    }
                }
            }
        }
    );

Git login into are secrets.
Pulumi up succeeds, and I can see secrets in the console like so:

"password": {
       "4dabf18193072939515e22adb298388d": "1b47061264138c4ac30d75fd1eb44270",
       "ciphertext": "AAABAAT6I4md3+xjlqIQf1Lntt+R9PomYXFZdg2RSViuWP2CWEw3k5QN"
     },
     "username": {
       "4dabf18193072939515e22adb298388d": "1b47061264138c4ac30d75fd1eb44270",
       "ciphertext": "AAABABfTbRhhdObvZTKqcY0wxObHcONld3QOXZz1GzdhNASu401yqEdi"
     }

When I do pulumi refresh, it wants to update agentPooId and sourceContext, and result looks like this

      "basicAuth": {
        "password": {},
        "username": {}
      }

So Read operation breaks these secrets, which is why pulumi up shows diff and actually fails after that, failing to read empty object where it expected a string or a secret.

@IaroslavTitov
Copy link
Contributor

Had a meeting to discuss this issue, review design doc and agreed on a gameplan described in the doc. Will proceed with implementation.

@IaroslavTitov IaroslavTitov modified the milestones: 0.104, 0.105 May 28, 2024
@IaroslavTitov
Copy link
Contributor

Create this issue https://github.com/pulumi/pulumi-service/issues/19990 for first part of the plan. I will use this issue for tracking change in PSP itself.

@IaroslavTitov
Copy link
Contributor

Created Sub-issue #299

PRs necessary for next step:
https://github.com/pulumi/pulumi-service/pull/20116
#298

@cleverguy25 cleverguy25 modified the milestones: 0.105, 0.106 Jun 10, 2024
@mikhailshilkov mikhailshilkov added the customer/feedback Feedback from customers label Jun 13, 2024
IaroslavTitov added a commit that referenced this issue Jun 26, 2024
### Note: there is an alternative implementation of this PR -
#320

### Summary

- Added logic to save ciphertext into the output properties for secret
values, allowing comparison on refresh of just ciphertext, fixing
#123
- Import now works as well, including code generation (with dummy values
for secrets)
- Migrated to new PUT API and updated client to actually return
DeploymentSettings

### Testing
- Tested pulumi up, refresh, import and up from previous version of the
provider (for unchanged DS inputs, migrating to this new way of saving
will require refresh and then up)

Example TS program (Sadly can't use Dotnet, due to bug with maps):
```
const settings = new service.DeploymentSettings("deployment_settings", {
  organization: "IaroslavTitov",
  project: "PulumiDotnet",
  stack: "SdkTest5",
  operationContext: {
    environmentVariables: {
      TEST_VAR: "fooa",
      SECRET_VAR: config.requireSecret("my_secret"),
    }
  },
  sourceContext: {
    git: {
        repoUrl: "https://github.com/pulumi/deploy-demos.git",
        branch: "refs/heads/main",
        repoDir: "pulumi-programs/simple-resource",
        gitAuth: {
            sshAuth: {
                sshPrivateKey: "privatekey",
                password: secret,
            }
        }
    }
}
});
```

Secret resource values end up with just cipher, while plaintext is
stored in inputs:
```
      "sshAuth": {
        "password": "AAABAD6/2Nroj62qORoHOLofFOkRhdUNwCAYeC86nABU/G4AO5I7Fw==",
        "sshPrivateKey": "AAABABqRIQ1bZbvU/hrlpX1Rh9sj9OCyArjG0SUILPQmb0KSCFIrz6bK"
      }
```

Passwords and sshKey are forced into twin secrets, Environment Variables
are optionally twin secrets, everything else uses normal Pulumi
workflows, because they are not secret in Pulumi Service.

Import of the above code generates successfully with dummy values for
secrets:
```
const ds1 = new pulumiservice.DeploymentSettings("ds1", {
    operationContext: {
        environmentVariables: {
            SECRET_VAR: pulumi.secret("<REPLACE WITH ACTUAL SECRET VALUE>"),
            TEST_VAR: "fooa",
        },
    },
    organization: "IaroslavTitov",
    project: "PulumiDotnet",
    sourceContext: {
        git: {
            branch: "refs/heads/main",
            gitAuth: {
                sshAuth: {
                    password: pulumi.secret("<REPLACE WITH ACTUAL SECRET VALUE>"),
                    sshPrivateKey: pulumi.secret("<REPLACE WITH ACTUAL SECRET VALUE>"),
                },
            },
            repoDir: "pulumi-programs/simple-resource",
            repoUrl: "https://github.com/pulumi/deploy-demos.git",
        },
    },
    stack: "SdkTest5",
}, {
    protect: true,
});
```
@IaroslavTitov IaroslavTitov added the resolution/fixed This issue was fixed label Jun 26, 2024
@IaroslavTitov
Copy link
Contributor

Finally merged in the last part, resolving!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-bash-candidate customer/feedback Feedback from customers kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Projects
None yet
Development

No branches or pull requests

4 participants