-
Notifications
You must be signed in to change notification settings - Fork 8
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
Fix the templating of secret variables in github pipelines #56
base: main
Are you sure you want to change the base?
Conversation
# Uncomment this when using Gitlab | ||
# GITOPS_AUTH_USERNAME: ${{ secrets.GITOPS_AUTH_USERNAME }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's silly to include this here, so I'll think of some exclusion mechanism (maybe just ignore this one specific secret directly in the template code)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's silly to include this here, so I'll think of some exclusion mechanism (maybe just ignore this one specific secret directly in the template code)
I was thinking we automatically include if the repo is gitlab ... Its kind of a pain to have to uncomment it... We can fix automate in the generated templates
See this https://github.com/redhat-appstudio/tssc-sample-templates/blob/main/skeleton/gitops-template/components/http/overlays/development/source-repository.yaml as an example
In this repo, we have to generate this code in the jenkinsfile for use in the tssc-sample-template ( template generating code to be expanded later(
{%- if values.hostType == 'Gitlab' %}
GITOPS_AUTH_USERNAME: ${{ secrets.GITOPS_AUTH_USERNAME }}
{%- endif %}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the GH actions pipeline, so the repo is never Gitlab (which is what I meant by "it's silly to include this")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the GH actions pipeline, so the repo is never Gitlab (which is what I meant by "it's silly to include this")
Agree.
We're talking about a two things.
- automatically adding the line if the repo the jenkinsfile is in fact a gitlab repo. We can do that at template generation time when we know the destination git type and the user doen't need to undo the commenting out
- Your point that Github should not have it - the mechanism for that in the generator is fine but the case (1) would take care of it but I agree would look silly
We should do both
I noticed that the gitlab-ci pipelines don't set any variables explicitly, how does that work? Do all the org-wide variables just apply implicitly, even without being defined in the YAML? |
Not sure why it's inconsistent. Maybe the vars are set via the ./rhtap/env.sh file, so there's no need to set them again in the yaml. |
Yes, gitlab variables are available by default in the pipelines. There are some options to restrict some to protected branches and for PRs and to mask or allow visible values |
Not sure why this is needed, in Jenkins, when you use credentials QUAY_IO_CREDS = credentials('QUAY_IO_CREDS') it creates the other two. The code credentials ('VARIABLE_NAME') makes <VARIABLE_NAME>, <VARIABLE_NAME>_USR, <VARIABLE_NAME>_PSW |
In Jenkins yes, in Github no. So we either need to update build_secrets:
- name: QUAY_IO_CREDS
if: ci == "jenkins"
- name: QUAY_IO_CREDS_USR
if: ci != "jenkins"
- name: QUAY_IO_CREDS_PSW
if: ci != "jenkins" Or stop relying on Jenkins-specific behavior |
6512621
to
bc85404
Compare
I gave this a shot, see if you prefer this |
bc85404
to
7fa9e21
Compare
Don't hardcode the secrets, use the data from templates/data.yaml Note: this has replaced QUAY_IO_CREDS_{USR,PSW} with QUAY_IO_CREDS. That's not correct, to be fixed soon. Signed-off-by: Adam Cmiel <[email protected]>
Don't hardcode the secrets, use the data from templates/data.yaml Note that previously, the gitops pipeline used the same secrets as the source-repo build pipeline. It probably shouldn't have. Signed-off-by: Adam Cmiel <[email protected]>
In templates/data.yaml, add an 'if' attribute to secrets. It can be arbitrary javascript code and can make use of the globals set in render.cjs in setupGlobals. In template files, use eval_if_condition to evaluate the condition. Signed-off-by: Adam Cmiel <[email protected]>
It is only used for Gitlab, it makes no sense to include it in the Github pipeline. Signed-off-by: Adam Cmiel <[email protected]>
The scripts expect QUAY_IO_CREDS_USR and QUAY_IO_CREDS_PSW variables. But templates/data.yaml defines only QUAY_IO_CREDS (which none of the scripts use). QUAY_IO_CREDS is a special case for Jenkins, where we create the secret as a username+password secret. Jenkins automatically injects the _USR and _PSW environment variables [1]. For pipelines other than Jenkins, set the required variables directly. [1]: https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#usernames-and-passwords Signed-off-by: Adam Cmiel <[email protected]>
7fa9e21
to
948dd85
Compare
Rebased on main, re-generated to include the TRUSTIFICATION secrets |
Adresses the TODOs in the workflow files about using the secrets list from templates/data.yaml