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

Feature request: Support secret creation for github actions #271

Closed
gjambet opened this issue Aug 21, 2019 · 26 comments
Closed

Feature request: Support secret creation for github actions #271

gjambet opened this issue Aug 21, 2019 · 26 comments
Labels
New resource size/M Status: Up for grabs Issues that are ready to be worked on by anyone thinking Type: Feature New feature or request

Comments

@gjambet
Copy link

gjambet commented Aug 21, 2019

Hi friends,

it would be super cool to be able to set secrets for actions through terraform while creating a repository. ;)

ty,

g. (happy action user)

@hronix
Copy link

hronix commented Sep 4, 2019

Yes please

@zzh8829
Copy link

zzh8829 commented Sep 27, 2019

github hasn't made api for secrets available yet, we have to wait for now

@iniinikoski
Copy link

Hi. Any updates on this - is the Secrets API still private...?

@gjambet
Copy link
Author

gjambet commented Jan 15, 2020

❤️

@jcudit
Copy link
Contributor

jcudit commented Jan 16, 2020

GitHub is aiming to make this endpoint available within the next few sprints. Mention me here if I don't post an update in a month or so.

@ajliv
Copy link

ajliv commented Jan 27, 2020

Secrets have been added to the GitHub API https://developer.github.com/v3/actions/secrets/

@martinssipenko
Copy link
Contributor

We now need to wait till Go GitHub client releases action secrets - google/go-github#1402

@bkamin29
Copy link

bkamin29 commented Feb 3, 2020

+1

@btkostner
Copy link
Contributor

It looks like it was merged google/go-github#1402 (comment) and released in the v29.0.3 tag.

@martinssipenko
Copy link
Contributor

I think we should also wait for #342 before we start implementing this one.

@martinssipenko
Copy link
Contributor

martinssipenko commented Feb 11, 2020

What do we think about usage? Should action secrets be a new resource - github_repository_action_secret and be used as follows?

resource "github_repository_action_secret" "foo" {
    repository = "${github_repository.repo.name}"
    name       = "FOO"
    secret     = "plain secret"
}

@hazcod
Copy link

hazcod commented Feb 11, 2020

Is there a way to provide ciphertexts in terraform and supply the key via an environment variable?
I can imagine it's problematic to store plaintext github secrets in terraform files ... which might be located on github again.

@martinssipenko
Copy link
Contributor

martinssipenko commented Feb 11, 2020

@hazcod I think one option would be that resource accepts two conflicting arguments - secret and encrypted_secret, The secret could be used to pass plain text value which would be encrypted by terraform using GitHubs public key. The encrypted_secret would accept already encrypted value and leave the encryption to the user.

Off topic: In order to not store secrets in terraform files I use an approach where I store secrets somewhere else, and then use a data provider to get the secret values from there. In that case I only need to reference the value from data source in my TF resources. Secrets are managed manually.

@martinssipenko
Copy link
Contributor

@radeksimko @jcudit @paultyng what are your thoughts on this?

@tgermain
Copy link
Contributor

Note for the implementation: how to know if a secret has been changed and need to be updated by terraform ?

The secret API does not offer a way to read the content of a secret (normal) but return the created_at and updated_at date.

Should we store at least the updated_at date in terraform state and when we refresh terraform state (before a plan for instance) we get the secret and compare its update_at date with the one in the state.
A difference in those dates would indicate the secret was updated since the last time terraform interact with. What do you think?

@martinssipenko
Copy link
Contributor

Another option is that terraform does not detect and repair "drift" on this resource in case the data is updated or deleted outside of Terraform. I think it might also be possible to not store secrets in state, but instead store a hash value of the secret, in case current value hash does not match hash stored in state an update should be performed.

@StephenWithPH
Copy link

A lurker (who wants this feature) chiming in...

I suggest not trying to get too clever regarding secrets in state. I often treat the Terraform Vault Provider as a guide for the official-ish Hashicorp way of doing things in Terraform.

Interacting with Vault from Terraform causes any secrets that you read and write to be persisted in both Terraform's state file and in any generated plan files. For any Terraform module that reads or writes Vault secrets, these files should be treated as sensitive and protected accordingly.

(https://www.terraform.io/docs/providers/vault/index.html)

Directly on the label, they disclaim any cleverness to protect secrets.

I think Terraform core offers enough ways to protect secrets. The combination of using remote state and an encryption-enabled backend seems sufficient. See https://www.terraform.io/docs/state/sensitive-data.html.

@tgermain
Copy link
Contributor

Indeed @StephenWithPH , state is already sensitive so we do not have to be too clever using hash in state (instead of plaintext values).

Another option is that terraform does not detect and repair "drift" on this resource in case the data is updated or deleted outside of Terraform.

This is also fine if it is clearly mentioned in the doc of the resource.
In case of doubts, you can always taint the doubtful resource in your terraform and recreate it. Terraform is your source of truth so manuals changes outside of it should be committed in terraform if they are meant to be permanent.

@senare
Copy link

senare commented Feb 14, 2020

Nice to see that this is being worked on!

imho ... just get it done ... KISS

@jcudit jcudit added Type: Feature New feature or request Status: Up for grabs Issues that are ready to be worked on by anyone New resource size/M thinking labels Feb 18, 2020
@benj-fletch
Copy link
Contributor

Hi, I'd like to take on this as we have a requirement for it in our organisation.
I think that we'd need to merge in https://github.com/terraform-providers/terraform-provider-github/pull/342 before work can be undertaken here, however, since v29 of go-github contains the calls we would need to utilise.
If it's ok, I'll start work on this in a branch of master merged with https://github.com/terraform-providers/terraform-provider-github/pull/342 and we can go from there?

@martinssipenko
Copy link
Contributor

@benj-fletch if you need any help, feel free to ask me.

@benj-fletch
Copy link
Contributor

benj-fletch commented Feb 18, 2020

@martinssipenko Thanks!
I think from reading the above comments I'll keep it relatively simple and allow the user of the resource to protect their secrets as they see fit (where possible). I need to see what is available to configure on the API and work on that basis.
EDIT: I'll be making changes here for those interested in tracking progress.

@jcudit
Copy link
Contributor

jcudit commented Feb 18, 2020

@benj-fletch my only ask on this one is to try to keep things forward compatible with these related enhancements. I'm 👍 on designing for overall Actions support rather than just the secret functionality.

@benj-fletch
Copy link
Contributor

@jcudit Sure thing, I will try my best to do so!

@techjacker
Copy link

Any idea when this will get merged? Would be very handy feature

jcudit pushed a commit that referenced this issue Mar 20, 2020
jcudit pushed a commit that referenced this issue Mar 25, 2020
@benj-fletch
Copy link
Contributor

I believe that this ticket can be closed now, following the merge of #362 ?

@jcudit jcudit closed this as completed Apr 20, 2020
kfcampbell pushed a commit to kfcampbell/terraform-provider-github that referenced this issue Jul 26, 2022
kfcampbell pushed a commit to kfcampbell/terraform-provider-github that referenced this issue Jul 26, 2022
kfcampbell pushed a commit to kfcampbell/terraform-provider-github that referenced this issue Jul 26, 2022
…update-to-go-github-v29-0-3

Updated to go-github v29.0.3
kfcampbell pushed a commit to kfcampbell/terraform-provider-github that referenced this issue Jul 26, 2022
integrationsGH-271 - Added actions_public_key data resource


integrationsGH-271 - Added actions_secrets data source

Further testing is required on this data source

integrationsGH-271 - Added actions_secret resource


integrationsGH-271 - Adding actions_secret resource


documentation updates


Fix formatting

Updates following PR comments


Updates following PR comments


integrationsGH-271 - Resolving more PR comments


Updating documentation


integrationsGH-271 - removing references to old TF SDK
kfcampbell pushed a commit to kfcampbell/terraform-provider-github that referenced this issue Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New resource size/M Status: Up for grabs Issues that are ready to be worked on by anyone thinking Type: Feature New feature or request
Projects
None yet
Development

No branches or pull requests