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

Secrets refactoring #650

Merged
merged 106 commits into from
Aug 9, 2023
Merged

Secrets refactoring #650

merged 106 commits into from
Aug 9, 2023

Conversation

freddydk
Copy link
Contributor

@freddydk freddydk commented Aug 7, 2023

With this PR, secrets are refactored kind of what Settings were in #640
Additionally a few bug-fixes were found and included.

ReadSecrets will create an environment variable called Secrets, which contains all requested secrets encoded with base64.
Secrets are no longer created as individual secrets.
All Secrets requested during the call to ReadSecrets will be available in $env:Secrets - empty if the secret doesn't exist.

Part of this refactoring was also to ensure that ReadSecrets and DetermineArtifactUrl didn't have to rewrite the settings environment variable.

ReadSecrets will now determine which secrets are used by AppDependencyProbingPaths and include those in $env:Secrets - and then DownloadProjectDependencies will use the value of the secret to download the dependencies.

ReadSettings in CI/CD will ask for the value of the artifact setting to be read.
DetermineArtifactUrl will now (based on this) determine the artifactUrl and set the environment variable to the "final" value.
RunPipeline will now take artifact as a parameter and use env:artifact as the value.

Additional refactoring, which will be done in separate PRs:

  • Split AnalyzeRepo into a series of functions for analyzing specific areas of the repo (to avoid -doNotXXX)
  • Use $env:Settings instead of using ReadSettings inside actions
  • Add end 2 end tests for delivery and deployment testing the areas, which failed here
  • Add end 2 end tests for include in appDependencyProbingPaths
  • Add CI test, testing that all actions have a try/catch
  • in a few places, secrets are used in yaml files with fromJson(env.Secrets).ghTokenWorkflow - remove this and use $env:secrets inside the action instead

Bugs found during this refactoring:

Unify try/catch for actions

All Actions now have a code snippet in action.yaml, which sets errorpreference and uses try/catch to give good error messages with stack trace. try/catches inside the action.ps1 is only used for telemetry reasons.

DownloadProjectDependencies didn't work for appDependencyProbingPaths

The Download function didn't analyze the settings and used appDependencyProbingPaths as a json structure, which it wasn't. It was always failing, but silently due to a missing multiline symbol in run: in the action.yaml. It might still have worked as RunPipeline itself also was also analyzing appDependencyProbingPaths

Deploy and Deliver didn't work properly after the settings refactoring

After the Settings refactoring, where settings are no longer available as environment variables, Deploy and Deliver was using [System.Environment]::GetEnvironmentVariable to check for settings and secrets - this obviously doesn't work if settings and secrets are no longer individual environment variables.

RunPipeline was requesting wrong secrets

RunPipeline was asking for the StorageContext secret, which it didn't use - instead it needed applicationInsightsConnectionString, which it didn't get. With the new mechanism, we just use secrets.applicationInsightsConnectionString - and if that property is set, we know that we requested the secret.

CalculateArtifactNames were emitting both OUTPUT variables and ENV variables

And in the BuildALGoProject yaml file - some were used as output and some as ENV.
Now only OUTPUT variables are emitted and used all over.
BTW buildMode is output, but it seems like it is never used???

ReadSecrets was called with ghTokenWorkflow=${{ env.GHTOKENWORKFLOWSECRETNAME }}

In multiple places, ReadSecrets was called with ghTokenWorkflow=${{ env.GHTOKENWORKFLOWSECRETNAME }}. The problem is, that the mapping to another secret is done inside ReadSecrets and shouldn't be part of the call. The caller should just ask for GhTokenWorkflow secret and then he should get that secret set from Secrets or Azure KeyVault with whatever name it is mapped to.

Actions/DetermineArtifactUrl/DetermineArtifactUrl.ps1 Outdated Show resolved Hide resolved
Actions/DetermineArtifactUrl/DetermineArtifactUrl.ps1 Outdated Show resolved Hide resolved
Actions/ReadSecrets/ReadSecrets.ps1 Outdated Show resolved Hide resolved
Actions/ReadSettings/ReadSettings.ps1 Show resolved Hide resolved
Actions/RunPipeline/RunPipeline.ps1 Outdated Show resolved Hide resolved
freddydk and others added 3 commits August 9, 2023 13:29
Co-authored-by: Maria Zhelezova <43066499+mazhelez@users.noreply.github.com>
Actions/ReadSecrets/ReadSecrets.ps1 Dismissed Show dismissed Hide dismissed
@freddydk freddydk requested a review from mazhelez August 9, 2023 12:16
@freddydk freddydk marked this pull request as draft August 9, 2023 13:05
@freddydk freddydk marked this pull request as ready for review August 9, 2023 14:08
Copy link
Collaborator

@mazhelez mazhelez left a comment

Choose a reason for hiding this comment

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

There're still some low-hanging issues.

Actions/AL-Go-Helper.ps1 Outdated Show resolved Hide resolved
RELEASENOTES.md Outdated Show resolved Hide resolved
RELEASENOTES.md Outdated Show resolved Hide resolved
RELEASENOTES.md Outdated Show resolved Hide resolved
RELEASENOTES.md Outdated Show resolved Hide resolved
RELEASENOTES.md Outdated Show resolved Hide resolved
freddydk and others added 7 commits August 9, 2023 17:10
Co-authored-by: Maria Zhelezova <43066499+mazhelez@users.noreply.github.com>
Co-authored-by: Maria Zhelezova <43066499+mazhelez@users.noreply.github.com>
Co-authored-by: Maria Zhelezova <43066499+mazhelez@users.noreply.github.com>
Co-authored-by: Maria Zhelezova <43066499+mazhelez@users.noreply.github.com>
Co-authored-by: Maria Zhelezova <43066499+mazhelez@users.noreply.github.com>
@freddydk freddydk merged commit d15c25e into microsoft:main Aug 9, 2023
2 of 3 checks passed
@freddydk freddydk deleted the OnlyNeededSecrets branch September 5, 2023 18:51
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