Skip to content

Commit e49d9a1

Browse files
Add an IV to the codefresh-token secret (#205)
* Added IV to codefresh-token secret * naming fixes * encode bytes to base64 * fixes * bump * bump
1 parent c29ac53 commit e49d9a1

File tree

7 files changed

+42
-23
lines changed

7 files changed

+42
-23
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.191
1+
VERSION=v0.0.192
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

cmd/commands/runtime.go

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ package commands
3030

3131
import (
3232
"context"
33+
"crypto/rand"
34+
"encoding/hex"
3335
"fmt"
36+
"io"
3437
"os"
3538
"strconv"
3639
"strings"
@@ -81,6 +84,7 @@ type (
8184
RuntimeInstallOptions struct {
8285
RuntimeName string
8386
RuntimeToken string
87+
RuntimeStoreIV string
8488
IngressHost string
8589
Insecure bool
8690
InstallDemoResources bool
@@ -118,16 +122,16 @@ type (
118122
}
119123

120124
summaryLogLevels string
121-
summaryLog struct {
125+
summaryLog struct {
122126
message string
123-
level summaryLogLevels
127+
level summaryLogLevels
124128
}
125129
)
126130

127131
const (
128132
Success summaryLogLevels = "Success"
129-
Failed summaryLogLevels = "Failed"
130-
Info summaryLogLevels = "Info"
133+
Failed summaryLogLevels = "Failed"
134+
Info summaryLogLevels = "Info"
131135
)
132136

133137
var summaryArr []summaryLog
@@ -313,14 +317,20 @@ func getComponents(rt *runtime.Runtime, opts *RuntimeInstallOptions) []string {
313317
return componentNames
314318
}
315319

316-
func createRuntimeOnPlatform(ctx context.Context, opts *model.RuntimeInstallationArgs) (string, error) {
320+
func createRuntimeOnPlatform(ctx context.Context, opts *model.RuntimeInstallationArgs) (string, string, error) {
317321
runtimeCreationResponse, err := cfConfig.NewClient().V2().Runtime().Create(ctx, opts)
322+
if err != nil {
323+
return "", "", fmt.Errorf("failed to create a new runtime: %s. Error: %w", opts.RuntimeName, err)
324+
}
318325

326+
const IV_LENGTH = 16
327+
iv := make([]byte, IV_LENGTH)
328+
_, err = io.ReadFull(rand.Reader, iv)
319329
if err != nil {
320-
return "", fmt.Errorf("failed to create a new runtime: %s. Error: %w", opts.RuntimeName, err)
330+
return "", "", fmt.Errorf("failed to create an initialization vector: %s. Error: %w", opts.RuntimeName, err)
321331
}
322332

323-
return runtimeCreationResponse.NewAccessToken, nil
333+
return runtimeCreationResponse.NewAccessToken, hex.EncodeToString(iv), nil
324334
}
325335

326336
func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
@@ -353,7 +363,7 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
353363

354364
defer postInstallationHandler(ctx, opts, &err)
355365

356-
token, err := createRuntimeOnPlatform(ctx, &model.RuntimeInstallationArgs{
366+
token, iv, err := createRuntimeOnPlatform(ctx, &model.RuntimeInstallationArgs{
357367
RuntimeName: opts.RuntimeName,
358368
Cluster: server,
359369
RuntimeVersion: runtimeVersion,
@@ -367,6 +377,7 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
367377
}
368378

369379
opts.RuntimeToken = token
380+
opts.RuntimeStoreIV = iv
370381
rt.Spec.Cluster = server
371382
rt.Spec.IngressHost = opts.IngressHost
372383
rt.Spec.Repo = opts.InsCloneOpts.Repo
@@ -1155,7 +1166,7 @@ func configureAppProxy(ctx context.Context, opts *RuntimeInstallOptions, rt *run
11551166
}
11561167

11571168
func createEventsReporter(ctx context.Context, cloneOpts *git.CloneOptions, opts *RuntimeInstallOptions, rt *runtime.Runtime) error {
1158-
runtimeTokenSecret, err := getRuntimeTokenSecret(opts.RuntimeName, opts.RuntimeToken)
1169+
runtimeTokenSecret, err := getRuntimeTokenSecret(opts.RuntimeName, opts.RuntimeToken, opts.RuntimeStoreIV)
11591170
if err != nil {
11601171
return fmt.Errorf("failed to create codefresh token secret: %w", err)
11611172
}
@@ -1289,7 +1300,7 @@ var getProjectInfoFromFile = func(repofs fs.FS, name string) (*argocdv1alpha1.Ap
12891300
return proj, appSet, nil
12901301
}
12911302

1292-
func getRuntimeTokenSecret(namespace string, token string) ([]byte, error) {
1303+
func getRuntimeTokenSecret(namespace string, token string, iv string) ([]byte, error) {
12931304
return yaml.Marshal(&v1.Secret{
12941305
TypeMeta: metav1.TypeMeta{
12951306
APIVersion: "v1",
@@ -1300,7 +1311,8 @@ func getRuntimeTokenSecret(namespace string, token string) ([]byte, error) {
13001311
Namespace: namespace,
13011312
},
13021313
Data: map[string][]byte{
1303-
store.Get().CFTokenSecretKey: []byte(token),
1314+
store.Get().CFTokenSecretKey: []byte(token),
1315+
store.Get().CFStoreIVSecretKey: []byte(iv),
13041316
},
13051317
})
13061318
}
@@ -1514,12 +1526,12 @@ func postInstallationHandler(ctx context.Context, opts *RuntimeInstallOptions, e
15141526
log.G(ctx).Warn("installation failed, performing installation rollback")
15151527
err := RunRuntimeUninstall(ctx, &RuntimeUninstallOptions{
15161528
RuntimeName: opts.RuntimeName,
1517-
Timeout: store.Get().WaitTimeout,
1518-
CloneOpts: opts.InsCloneOpts,
1529+
Timeout: store.Get().WaitTimeout,
1530+
CloneOpts: opts.InsCloneOpts,
15191531
KubeFactory: opts.KubeFactory,
1520-
SkipChecks: true,
1521-
Force: true,
1522-
FastExit: false,
1532+
SkipChecks: true,
1533+
Force: true,
1534+
FastExit: false,
15231535
})
15241536
if err != nil {
15251537
log.G(ctx).Errorf("installation rollback failed: %w", err)
@@ -1529,7 +1541,7 @@ func postInstallationHandler(ctx context.Context, opts *RuntimeInstallOptions, e
15291541
printSummaryToUser()
15301542
}
15311543

1532-
func appendLogToSummary(message string, err error){
1544+
func appendLogToSummary(message string, err error) {
15331545
if err != nil {
15341546
summaryArr = append(summaryArr, summaryLog{message, Failed})
15351547
} else {
@@ -1546,7 +1558,7 @@ func printSummaryToUser() {
15461558
} else {
15471559
fmt.Printf("%s\n", summaryArr[i].message)
15481560
}
1549-
}
1561+
}
15501562
//clear array to avoid double printing
15511563
summaryArr = []summaryLog{}
15521564
}

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cf version
2323

2424
```bash
2525
# download and extract the binary
26-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.191/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.192/cf-linux-amd64.tar.gz | tar zx
2727

2828
# move the binary to your $PATH
2929
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -36,7 +36,7 @@ cf version
3636

3737
```bash
3838
# download and extract the binary
39-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.191/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.192/cf-darwin-amd64.tar.gz | tar zx
4040

4141
# move the binary to your $PATH
4242
mv ./cf-darwin-amd64 /usr/local/bin/cf

manifests/app-proxy/app-proxy.deploy.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ spec:
8686
secretKeyRef:
8787
name: codefresh-token
8888
key: token
89+
- name: RUNTIME_STORE_IV
90+
valueFrom:
91+
secretKeyRef:
92+
name: codefresh-token
93+
key: encryptionIV
8994
- name: STORE_BACKEND
9095
valueFrom:
9196
configMapKeyRef:

manifests/app-proxy/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Kustomization
33
images:
44
- name: quay.io/codefresh/cap-app-proxy
55
newName: quay.io/codefresh/cap-app-proxy
6-
newTag: v0.0.19
6+
newTag: v0.0.20
77
resources:
88
- app-proxy.deploy.yaml
99
- app-proxy.svc.yaml

manifests/runtime.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: "{{ namespace }}"
66
spec:
77
defVersion: 1.0.0
8-
version: 0.0.191
8+
version: 0.0.192
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

pkg/store/store.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ type Store struct {
7575
CFRuntimeType string
7676
CFTokenSecret string
7777
CFTokenSecretKey string
78+
CFStoreIVSecretKey string
7879
CodefreshCM string
7980
CodefreshSA string
8081
ComponentsReporterName string
@@ -163,6 +164,7 @@ func init() {
163164
s.ArgoCDAgentReporterName = "argocd-agent"
164165
s.ArgoCDAgentSA = "argocd-agent"
165166
s.CFTokenSecretKey = "token"
167+
s.CFStoreIVSecretKey = "encryptionIV"
166168
s.CodefreshCM = "codefresh-cm"
167169
s.CodefreshSA = "codefresh-sa"
168170
s.ComponentsReporterName = "components-reporter"

0 commit comments

Comments
 (0)