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

Include envFrom in "how to use a Secret as an environment source" #8620

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jcjveraa
Copy link

@jcjveraa jcjveraa commented Mar 4, 2025

I suggest that using envFrom for well known secrets types is recommended (or at least documented as an option),

https://kubernetes.io/docs/concepts/configuration/secret/#basic-authentication-secret

Changes

I suggest that using envFrom for well known secrets types is recommended (or at least documented as an option) as it makes use of the existing 'typing' in kubernetes, and many times in practice secrets will be some form of (well known) authentication secret like https://kubernetes.io/docs/concepts/configuration/secret/#basic-authentication-secret.

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Has Docs if any changes are user facing, including updates to minimum requirements e.g. Kubernetes version bumps
  • [x ] Has Tests included if any functionality added or changed
  • pre-commit Passed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including functionality, content, code)
  • Has a kind label. You can add one by adding a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings). See some examples of good release notes.
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

NONE

I suggest that using envFrom for well known secrets types is recommended (or at least documented as an option),

https://kubernetes.io/docs/concepts/configuration/secret/#basic-authentication-secret
@tekton-robot tekton-robot added the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label Mar 4, 2025
Copy link

linux-foundation-easycla bot commented Mar 4, 2025

CLA Missing ID CLA Not Signed

@tekton-robot tekton-robot requested review from abayer and afrittoli March 4, 2025 20:09
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign abayer after the PR has been reviewed.
You can assign the PR to them by writing /assign @abayer in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Mar 4, 2025
@jcjveraa
Copy link
Author

jcjveraa commented Mar 4, 2025

/kind documentation

@tekton-robot tekton-robot added kind/documentation Categorizes issue or PR as related to documentation. release-note-none Denotes a PR that doesnt merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Mar 4, 2025
Copy link
Member

@AlanGreene AlanGreene left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @jcjveraa. I've added a couple of comments on the specific changes below, but also have some more general thoughts / questions.

The existing example is an actual functional task demonstrating use of the env approach to reading a value from a Secret. Would it make sense to leave that as-is, and instead add a second example showing the envFrom approach?

I'd be interested in others' thoughts on this. I think we should aim to keep the examples relatively simple yet realistic to clearly demonstrate the topic / feature, and avoid combining too many different pieces in a single example.

docs/tasks.md Outdated
envFrom:
- secretRef:
name: $(params.my-basic-auth-ssh-or-docker-type-secret-name}
# Using configMapRef works, but as al ConfigMaps are freeform this is not recommended
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this distinction is particularly useful or something Tekton should take a stance on. Secrets are also freeform, although there are some well-known / agreed shapes commonly used.

In either case, regardless of using a ConfigMap or a Secret, it would be up to the Task author to ensure the expected shape / content is documented.

Copy link
Author

@jcjveraa jcjveraa Mar 5, 2025

Choose a reason for hiding this comment

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

In our organisation we have some less experienced users that also (need to) make custom Tasks. I have noticed that giving 'complete but opinionated' examples tends to work best. In this particular case:

  • use the short envFrom syntax for well known secret types (and of course in the task-script itself then check if variables are set properly)
  • let the user know that configMapRef can also be done, nothing preventing it, but it might not be what you want as it makes it unclear what is injected as environmental variables exactly (you could get conflicts).

What do you prefer: remove the opinion, or inlcude it but spell it out more clearly in the text above the code example (which as you suggested would be a seperate header)? If the docs allow for a "tip-callout" markup, perhaps the "be careful with using envFrom with freeform Secrets/ConfigMaps as you might get more variables (from the Task user) than you expect" could be useful in such a tip-section?

docs/tasks.md Outdated
env:
- name: GOPATH
value: /workspace
- name: GITHUB_TOKEN
valueFrom:
secretKeyRef:
name: $(params.github-token-secret)
key: bot-token
key: $(params.github-token-secret-key)
Copy link
Member

Choose a reason for hiding this comment

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

This will not work as the param github-token-secret-key is not declared in spec.params. This applies to the other new params introduced above.

The examples should pass validation, and ideally actually be functional, so that users have a working base to start from.

Is making the key configurable necessary for the purposes of this example?

Copy link
Author

Choose a reason for hiding this comment

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

Apologies, you are right of course. This was the result of 'oh this would actually be better' just before I logged off and went to bed.

As to 'why parameterize' (if I had done it correctly): again I see users 'unneccesarily hardcoding things' based off of copying examples. Part of the 'power' of using Tekton vs just making a bash script that does it all lies in such as the parameterization of task inputs, so I'm used to 'fully parameterize' (with sane defaults) any example I write.

What I wanted to do/should have done before submitting the PR was add parameters above such as:

- name: github-token-secret-key
  type: string
  default: bot-token

Based on your comment, perhaps it would be better to keep it simple here and 'full parameterization with defaults' would be better placed in the 'actual code' example (which could be linked to from the text) as requested by @waveywaves ?

Copy link
Member

Choose a reason for hiding this comment

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

That sounds like a reasonable approach 👍

@jcjveraa
Copy link
Author

jcjveraa commented Mar 5, 2025

@AlanGreene Thanks for the feedback. I'll reply to your comments above, I expect to implement some changes reflecting your comments by this evening (including splitting it off to a different header to avoid combining topics).

note: if those changes are 'close to acceptable', I'm perfectly happy that my PR is edited by any of the maintainers to ensure consistent style.

@tekton-robot tekton-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 5, 2025
@jcjveraa
Copy link
Author

jcjveraa commented Mar 5, 2025

I'm fairly sure that the header-level for the section we're changing in this PR was wrong (see screenshot - the 'subheaders' have nothing to do with the first header), so I fixed these too now.

I've tested the minimal example yaml I've made on request by @waveywaves, see second screenshot.

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/documentation Categorizes issue or PR as related to documentation. release-note-none Denotes a PR that doesnt merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

4 participants