Skip to content

Commit eea8299

Browse files
authored
fix: unique admin password for gitea (#1940)
1 parent ab7b631 commit eea8299

File tree

7 files changed

+40
-20
lines changed

7 files changed

+40
-20
lines changed

helmfile.d/snippets/defaults.gotmpl

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
environments:
88
default:
99
values:
10-
- teamConfig:
10+
- apps:
11+
gitea:
12+
adminPassword: {{ randAlphaNum 20 }}
13+
teamConfig:
1114
{{- range $team := $teams }}
1215
{{ $team }}:
1316
apps:

helmfile.d/snippets/derived.gotmpl

+1-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ environments:
188188
password: {{ $a | get "harbor.registry.credentials.password" $v.otomi.adminPassword }}
189189
gitea:
190190
enabled: true
191-
adminPassword: {{ $a | get "gitea.adminPassword" $v.otomi.adminPassword }}
192191
keycloak:
193192
enabled: true
194193
address: {{ $keycloakBaseUrl }}
@@ -215,4 +214,4 @@ environments:
215214
otomi:
216215
version: {{ $otomiTag }}
217216
versions: {{- $versions | toYaml | nindent 10 }}
218-
- ../core.yaml
217+
- ../core.yaml

src/cmd/apply.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const applyAll = async () => {
114114

115115
await upgrade({ when: 'post' })
116116
if (!(env.isDev && env.DISABLE_SYNC)) {
117-
await commit()
117+
await commit(initialInstall)
118118
if (initialInstall) {
119119
await hf(
120120
{

src/cmd/commit.ts

+28-9
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,39 @@ const commitAndPush = async (values: Record<string, any>, branch: string): Promi
5050
return
5151
}
5252
if (values._derived?.untrustedCA) process.env.GIT_SSL_NO_VERIFY = '1'
53-
d.log('git config:')
54-
await $`cat .git/config`
55-
await $`git push -u origin ${branch}`
53+
await retry(
54+
async () => {
55+
try {
56+
cd(env.ENV_DIR)
57+
await $`git push -u origin ${branch}`
58+
} catch (e) {
59+
d.warn(`The values repository is not yet reachable. Retrying.`)
60+
throw e
61+
}
62+
},
63+
{
64+
retries: 20,
65+
maxTimeout: 30000,
66+
},
67+
)
5668
d.log('Successfully pushed the updated values')
5769
}
5870

59-
export const commit = async (): Promise<void> => {
71+
export const commit = async (initialInstall: boolean): Promise<void> => {
6072
const d = terminal(`cmd:${cmdName}:commit`)
6173
await validateValues()
6274
d.info('Preparing values')
6375
const values = (await hfValues()) as Record<string, any>
64-
// we call this here again, as we might not have completed (happens upon first install):
65-
await bootstrapGit(values)
66-
const { branch, remote } = getRepo(values)
76+
const { branch, remote, username, email } = getRepo(values)
77+
if (initialInstall) {
78+
// we call this here again, as we might not have completed (happens upon first install):
79+
await bootstrapGit(values)
80+
} else {
81+
cd(env.ENV_DIR)
82+
await setIdentity(username, email)
83+
// the url might need updating (e.g. if credentials changed)
84+
await $`git remote set-url origin ${remote}`
85+
}
6786
// lets wait until the remote is ready
6887
if (values?.apps!.gitea!.enabled ?? true) {
6988
await waitTillGitRepoAvailable(remote)
@@ -100,7 +119,7 @@ export const cloneOtomiChartsInGitea = async (): Promise<void> => {
100119
await $`rm -f .gitignore`
101120
await $`rm -f LICENSE`
102121
await $`git init`
103-
await setIdentity(username, password, email)
122+
await setIdentity(username, email)
104123
await $`git checkout -b main`
105124
await $`git add .`
106125
await $`git commit -m "first commit"`
@@ -222,6 +241,6 @@ export const module = {
222241
handler: async (argv: Arguments): Promise<void> => {
223242
setParsedArgs(argv)
224243
await prepareEnvironment({ skipKubeContextCheck: true })
225-
await commit()
244+
await commit(true)
226245
},
227246
}

src/common/bootstrap.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ export const prepareDomainSuffix = async (inValues: Record<string, any> | undefi
3030
}
3131
}
3232

33-
export const setIdentity = async (username, password, email) => {
33+
export const setIdentity = async (username, email) => {
3434
await $`git config --local user.name ${username}`.nothrow().quiet()
35-
await $`git config --local user.password ${password}`.nothrow().quiet()
3635
await $`git config --local user.email ${email}`.nothrow().quiet()
3736
}
3837
/**
@@ -51,11 +50,11 @@ export const bootstrapGit = async (inValues?: Record<string, any>): Promise<void
5150
// we couldn't find the domainSuffix in the values, so create it
5251
await prepareDomainSuffix(values)
5352
}
54-
const { remote, branch, email, username, password } = getRepo(values)
53+
const { remote, branch, email, username } = getRepo(values)
5554
cd(env.ENV_DIR)
5655
if (await pathExists(`${env.ENV_DIR}/.git`)) {
5756
d.info(`Git repo was already bootstrapped, setting identity just in case`)
58-
await setIdentity(username, password, email)
57+
await setIdentity(username, email)
5958
return
6059
}
6160
// we don't care about ssl verification as repo endpoint is either ours or user input
@@ -106,7 +105,7 @@ export const bootstrapGit = async (inValues?: Record<string, any>): Promise<void
106105
await $`git config --global --add safe.directory ${env.ENV_DIR}`.nothrow().quiet()
107106
}
108107

109-
await setIdentity(username, password, email)
108+
await setIdentity(username, email)
110109

111110
if (!hasCommits) {
112111
await $`git checkout -b ${branch}`.nothrow().quiet()

src/common/values.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export const getRepo = (values: Record<string, any>): Repo => {
8383
branch = otomiApiGit?.branch ?? branch
8484
} else {
8585
username = 'otomi-admin'
86-
password = values?.apps?.gitea?.adminPassword ?? values?.otomi?.adminPassword
86+
password = values?.apps?.gitea?.adminPassword
8787
8888
const giteaUrl = `gitea-http.gitea.svc.cluster.local:3000`
8989
const giteaOrg = 'otomi'

values-schema.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,7 @@ properties:
18211821
$ref: '#/definitions/rawValues'
18221822
adminPassword:
18231823
type: string
1824-
x-secret: ''
1824+
x-secret: '{{ randAlphaNum 20 }}'
18251825
postgresqlPassword:
18261826
type: string
18271827
description: This password was generated and cannot be changed without manual intervention.

0 commit comments

Comments
 (0)