Skip to content

GitHub provider (supersedes #3014)#3115

Merged
Skarlso merged 10 commits intoexternal-secrets:mainfrom
mike-serchenia:github-provider-0
Apr 3, 2024
Merged

GitHub provider (supersedes #3014)#3115
Skarlso merged 10 commits intoexternal-secrets:mainfrom
mike-serchenia:github-provider-0

Conversation

@mike-serchenia
Copy link
Copy Markdown
Contributor

I'd like to propose new provider Github.

I uses Github application privateKey and appID to get github accessToken of format ghs_* The token can be used to access GH repositories, pull/push to registry, etc.

Can be used for tekton auth with GH instead of using personal access tokens'

Checklist

  • I have read the contribution guidelines
  • All commits are signed with git commit --signoff
  • My changes have reasonable test coverage
  • All tests pass with make test
  • I ensured my PR is ready for review with make reviewable

to replace #3014 with multiple merge conflicts

mike-serchenia and others added 2 commits February 5, 2024 13:48
Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>
@mike-serchenia mike-serchenia requested a review from a team as a code owner February 5, 2024 17:54
@mike-serchenia mike-serchenia requested a review from moolen February 5, 2024 17:54
@mike-serchenia mike-serchenia mentioned this pull request Feb 5, 2024
5 tasks
Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>
Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Feb 5, 2024

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@shuheiktgw shuheiktgw mentioned this pull request Feb 6, 2024
5 tasks
@gusfcarvalho
Copy link
Copy Markdown
Member

hi @mike-serchenia, thanks for your contribution. Just to be clear, here the idea is to create app tokens for a given application installation, right?

If that's the case, this is better suited to be a generator, as we expect tokens to rotate whenever a new refreshInterval cycle happens.

@gusfcarvalho
Copy link
Copy Markdown
Member

With the current approach, there will never be any two intervals where the data hash will remain the same, this would break some features and assurances we have when it comes to SecretStores as providers.

@gusfcarvalho
Copy link
Copy Markdown
Member

(I also do not see it as a superseeding PR to #2843, as that one was about pushing to Github actions secrets :)

@mike-serchenia
Copy link
Copy Markdown
Contributor Author

hi @mike-serchenia, thanks for your contribution. Just to be clear, here the idea is to create app tokens for a given application installation, right?

If that's the case, this is better suited to be a generator, as we expect tokens to rotate whenever a new refreshInterval cycle happens.

Hi!
looks like it, I'll refactor it and move to generators, need to educate myself first on how to work with generators. Should I open new PR or updating this on is fine?

@gusfcarvalho
Copy link
Copy Markdown
Member

feel free to update this one 😄

@JorgenSQ
Copy link
Copy Markdown

JorgenSQ commented Mar 7, 2024

Still waiting for this with great suspense!

@mike-serchenia
Copy link
Copy Markdown
Contributor Author

I'll get back to it hopefully next week.

mike-serchenia and others added 5 commits March 11, 2024 21:10
Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>
Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>
Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>
Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>
@mike-serchenia
Copy link
Copy Markdown
Contributor Author

Hi @gusfcarvalho

can you check my PR and approve if it looks good?

return nil, fmt.Errorf("error creating request: %w", err)
}
// Github api expects POST request
req, err := http.NewRequestWithContext(context.TODO(), "POST", gh.URL, http.NoBody)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pass in the context from generate.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Replace "POST" with http.MethodPost.


// git access token
var gat map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&gat); err != nil && resp.StatusCode < 300 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Below 300 but above 199.


accessToken, ok := gat["token"].(string)
if !ok {
return nil, fmt.Errorf("token is not a string")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Technically... token is not a string or token key doesn't exist. :)

func newGHClient(ctx context.Context, k client.Client, n string, hc *http.Client,
js *apiextensions.JSON) (*Github, error) {
if hc == nil {
hc = &http.Client{}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Set up some timeouts.

hc = &http.Server{
    ReadTimeout: 5 * time.Second,
    WriteTimeout: 10 * time.Second,
}

gh := &Github{Kube: k, Namespace: n, HTTP: hc}

ghPath := fmt.Sprintf("/app/installations/%s/access_tokens", res.Spec.InstallID)
gh.URL = "https://api.github.com" + ghPath
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This URL should be configurable by the user since this can be enterprise or an on-prem installation.

Copy link
Copy Markdown
Contributor

@Skarlso Skarlso Mar 12, 2024

Choose a reason for hiding this comment

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

Wait a second... This URL should already be configured. Are you overwriting it here? 🤔 Why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

url can be set by
apis/generators/v1alpha1/generator_github.go:25

type GithubAccessTokenSpec struct {
	// URL configures the Github instance URL. Defaults to https://github.com/.
	URL       string `json:"url,omitempty"`

replaced with:

const (
	defaultGithubAPI     = "https://api.github.com"
) 
gh.URL = defaultGithubAPI + ghPath
if res.Spec.URL != "" {
	gh.URL = res.Spec.URL + ghPath
}

if err != nil || storeBytes == nil {
return "", fmt.Errorf("failed to marshal store spec: %w", err)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why? :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is a great question :), thank you for pointing out

- "ecrauthorizationtokens"
- "fakes"
- "gcraccesstokens"
- "githubaccesstokens"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These are here twice. 🤔

Copy link
Copy Markdown
Contributor

@Skarlso Skarlso left a comment

Choose a reason for hiding this comment

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

Left you some review comments. :)

Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
1.0% Duplication on New Code

See analysis details on SonarCloud

@mike-serchenia
Copy link
Copy Markdown
Contributor Author

Left you some review comments. :)

Thank you for the comments! Just pushed commit addressing each comment.

@mike-serchenia mike-serchenia requested a review from Skarlso March 12, 2024 07:06
@Skarlso
Copy link
Copy Markdown
Contributor

Skarlso commented Mar 12, 2024

LGTM. @gusfcarvalho Is the new generator okay?

@mike-serchenia
Copy link
Copy Markdown
Contributor Author

@gusfcarvalho could you please check if the PR is okay or some changes are required?

@Skarlso Skarlso merged commit 8473161 into external-secrets:main Apr 3, 2024
@Skarlso
Copy link
Copy Markdown
Contributor

Skarlso commented Apr 3, 2024

As far as I understand, it looks okay. Let's hope I'm not wrong. :D

Bude8 pushed a commit to Bude8/external-secrets that referenced this pull request Jun 13, 2024
…3115)

* github provider signed, supersedes external-secrets#3014

Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>

* tests pass, + crd + docs

Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>

* fix sonarLint alert

Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>

* refactoring, replace secretStore with generator

Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>

* cosmetics + tst + lint pass

Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>

* docs

Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>

* clean-up + lint + test

Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>

* small refactor, fix issues left in comments

Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>

---------

Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>
Signed-off-by: Bude8 <henryblee8@gmail.com>
pacificcode pushed a commit to pacificcode/external-secrets that referenced this pull request Jul 3, 2024
…3115)

* github provider signed, supersedes external-secrets#3014

Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>

* tests pass, + crd + docs

Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>

* fix sonarLint alert

Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>

* refactoring, replace secretStore with generator

Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>

* cosmetics + tst + lint pass

Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>

* docs

Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>

* clean-up + lint + test

Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>

* small refactor, fix issues left in comments

Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>

---------

Signed-off-by: Mike Serchenia <michael_serchenia@epam.com>
Signed-off-by: Bill Hamilton <bill.hamilton@delinea.com>
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.

4 participants