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

fix: don't base64 decode secret strings #1683

Merged
merged 1 commit into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ Alternatively, you can install each controller stack into a unique namespace (re
- The organization level
- The enterprise level

Runners can be deployed as 1 of 2 abstractions:
Runners can be deployed as 1 of 2 abstractions:

- A `RunnerDeployment` (similar to k8s's `Deployments`, based on `Pods`)
- A `RunnerSet` (based on k8s's `StatefulSets`)
Expand Down Expand Up @@ -1786,9 +1786,11 @@ kind: RunnerDeployment
metadata:
namespace: org1-runners
spec:
githubAPICredentialsFrom:
secretRef:
name: org1-github-app
template:
spec:
githubAPICredentialsFrom:
secretRef:
name: org1-github-app
---
kind: HorizontalRunnerAutoscaler
metadata:
Expand Down
52 changes: 8 additions & 44 deletions controllers/multi_githubclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package controllers
import (
"context"
"crypto/sha1"
"encoding/base64"
"encoding/hex"
"fmt"
"sort"
Expand Down Expand Up @@ -270,73 +269,38 @@ func (c *MultiGitHubClient) derefClient(ns, secretName string, dependent *runner
}
}

func decodeBase64(s []byte) (string, error) {
enc := base64.RawStdEncoding
dbuf := make([]byte, enc.DecodedLen(len(s)))
n, err := enc.Decode(dbuf, []byte(s))
if err != nil {
return "", err
}

return string(dbuf[:n]), nil
}

func secretDataToGitHubClientConfig(data map[string][]byte) (*github.Config, error) {
var (
conf github.Config

err error
)

conf.URL, err = decodeBase64(data["github_url"])
if err != nil {
return nil, err
}
conf.URL = string(data["github_url"])

conf.UploadURL, err = decodeBase64(data["github_upload_url"])
if err != nil {
return nil, err
}
conf.UploadURL = string(data["github_upload_url"])

conf.EnterpriseURL, err = decodeBase64(data["github_enterprise_url"])
if err != nil {
return nil, err
}
conf.EnterpriseURL = string(data["github_enterprise_url"])

conf.RunnerGitHubURL, err = decodeBase64(data["github_runner_url"])
if err != nil {
return nil, err
}
conf.RunnerGitHubURL = string(data["github_runner_url"])

conf.Token, err = decodeBase64(data["github_token"])
if err != nil {
return nil, err
}
conf.Token = string(data["github_token"])

appID, err := decodeBase64(data["github_app_id"])
if err != nil {
return nil, err
}
appID := string(data["github_app_id"])

conf.AppID, err = strconv.ParseInt(appID, 10, 64)
if err != nil {
return nil, err
}

instID, err := decodeBase64(data["github_app_installation_id"])
if err != nil {
return nil, err
}
instID := string(data["github_app_installation_id"])

conf.AppInstallationID, err = strconv.ParseInt(instID, 10, 64)
if err != nil {
return nil, err
}

conf.AppPrivateKey, err = decodeBase64(data["github_app_private_key"])
if err != nil {
return nil, err
}
conf.AppPrivateKey = string(data["github_app_private_key"])

return &conf, nil
}
Expand Down