Jack Archer
10/28/2021, 5:37 PMapiVersion: v1
kind: ConfigMap
metadata:
name: cerbos-config
labels:
app: {{ .Values.name }}
data:
"config.yaml": |-
server:
httpListenAddr: ":{{ .Values.port }}"
grpcListenAddr: ":{{ .Values.grpcPort }}"
metricsEnabled: true
logRequestPayloads: true
playgroundEnabled: false
adminAPI:
enabled: true
adminCredentials:
username: {{ .Values.adminCredentials.username }}
passwordHash: {{ .Values.adminCredentials.passwordHash }}
storage:
driver: "disk"
disk:
directory: /work
I'm getting this error:
{
"log.level": "error",
"@timestamp": "2021-10-28T17:26:15.813Z",
"log.logger": "cerbos.server",
"message": "Failed to load configuration",
"error": "failed to create config provider: couldn't expand environment: default is empty for \"RFeXyZ\" (use \"\" for empty string)"
}
It seems to be from the uber config tool here:
<https://github.com/uber-go/config/blob/7eebe84240ad56046741394bf03b34129c07be12/expand.go#L75>
oguzhan
kubectl get cm cerbos-config -o yaml
?Jack Archer
10/28/2021, 5:47 PMJack Archer
10/28/2021, 5:48 PMkubectl get cm cerbos-config -o yaml
apiVersion: v1
data:
config.yaml: |-
server:
httpListenAddr: ":3592"
grpcListenAddr: ":3593"
metricsEnabled: true
logRequestPayloads: true
playgroundEnabled: false
adminAPI:
enabled: true
adminCredentials:
username: "cerbos"
passwordHash: "<pass>"
storage:
driver: "disk"
disk:
directory: "/work"
kind: ConfigMap
metadata:
annotations:
<http://meta.helm.sh/release-name|meta.helm.sh/release-name>: cerbos
<http://meta.helm.sh/release-namespace|meta.helm.sh/release-namespace>: default
creationTimestamp: "2021-10-27T21:06:58Z"
labels:
app: cerbos
<http://app.kubernetes.io/managed-by|app.kubernetes.io/managed-by>: Helm
name: cerbos-config
namespace: default
resourceVersion: "6445"
uid: 8d986610-c76f-48eb-9eec-fa68e66fd19b
oguzhan
Jack Archer
10/28/2021, 6:05 PMimagePullPolicy: Always
args:
- "server"
- "--config=/config/config.yaml"
- "--log-level={{ .Values.logLevel }}"
Jack Archer
10/28/2021, 6:19 PMJack Archer
10/28/2021, 6:19 PMconfig.Expand
option? I didn't see anything in the docs about configuring via env varsJack Archer
10/28/2021, 6:37 PMconfig.Expand
option is used to enable env var interpolation in the config file... see here:
https://github.com/cerbos/cerbos/blob/main/internal/config/config_test.go#L58
The error I was experiencing was due to the "$" char being included in the password hash string... uber-go/config
was trying to interpolate it as an env var
ctheJack Archer
10/28/2021, 6:38 PM$
the build succeededJack Archer
10/28/2021, 6:39 PMJack Archer
10/28/2021, 6:39 PMoguzhan
Jack Archer
10/28/2021, 6:54 PMCharith (Cerbos)
Jack Archer
10/28/2021, 6:58 PMCharith (Cerbos)
Jack Archer
10/28/2021, 7:00 PMJack Archer
10/28/2021, 7:00 PMCharith (Cerbos)
Jack Archer
10/28/2021, 7:03 PMJack Archer
10/28/2021, 7:03 PMecho "cerbosAdmin123" | htpasswd -niBC 10 cerbos | cut -d ':' -f 2
$2y$10$n9lOaESI15cOkpeeO7ISJOjY1IV3SCFbfTrDXomt2Y.plRMRmlSlq
Jack Archer
10/28/2021, 7:03 PMJack Archer
10/28/2021, 7:03 PM$
Charith (Cerbos)
Jack Archer
10/28/2021, 7:07 PMJack Archer
10/28/2021, 7:07 PMJack Archer
10/28/2021, 7:08 PMJack Archer
10/28/2021, 7:09 PMecho "cerbosAdmin123" | htpasswd -niBC 10 cerbos | cut -d ':' -f 2
$2y$10$zoVBUHm7YJu7Uj21WeeALOTObW1MQ0IxdjYBBwiv3i2j.BVPZAZ6C
Jack Archer
10/28/2021, 7:09 PMkubectl describe cm cerbos-config
Name: cerbos-config
Namespace: default
Labels: app=cerbos
<http://app.kubernetes.io/managed-by=Helm|app.kubernetes.io/managed-by=Helm>
Annotations: <http://meta.helm.sh/release-name|meta.helm.sh/release-name>: cerbos
<http://meta.helm.sh/release-namespace|meta.helm.sh/release-namespace>: default
Data
====
config.yaml:
----
server:
httpListenAddr: ":3592"
grpcListenAddr: ":3593"
metricsEnabled: true
logRequestPayloads: true
playgroundEnabled: false
adminAPI:
enabled: true
adminCredentials:
username: "cerbos"
passwordHash: "$2y$10$zoVBUHm7YJu7Uj21WeeALOTObW1MQ0IxdjYBBwiv3i2j.BVPZAZ6C"
storage:
driver: "disk"
disk:
directory: "/work"
Events: <none>
Charith (Cerbos)
Jack Archer
10/28/2021, 7:10 PMkubectl logs cerbos-77d8d74875-rntmk
{"log.level":"info","@timestamp":"2021-10-28T19:08:29.699Z","log.logger":"cerbos.server","message":"maxprocs: Updating GOMAXPROCS=1: using minimum allowed GOMAXPROCS"}
{"log.level":"error","@timestamp":"2021-10-28T19:08:29.700Z","log.logger":"cerbos.server","message":"Failed to load configuration","error":"failed to create config provider: couldn't expand environment: default is empty for \"zoVBUHm7YJu7Uj21WeeALOTObW1MQ0IxdjYBBwiv3i2j\" (use \"\" for empty string)"}
ERROR: failed to create config provider: couldn't expand environment: default is empty for "zoVBUHm7YJu7Uj21WeeALOTObW1MQ0IxdjYBBwiv3i2j" (use "" for empty string)
{"log.level":"info","@timestamp":"2021-10-28T19:08:29.701Z","log.logger":"cerbos.server","message":"maxprocs: Resetting GOMAXPROCS to 6"}
Charith (Cerbos)
Jack Archer
10/28/2021, 7:10 PM$zoVBUHm7YJu7Uj21WeeALOTObW1MQ0I => default is empty for \"zoVBUHm7YJu7Uj21WeeALOTObW1MQ0Ixdj
Jack Archer
10/28/2021, 7:11 PMoguzhan
...
// Expand allows variable references to take two forms: $VAR or
// ${VAR:default}.
...
Documentation for the config.Expand
function states $VAR
also expands the variable.Jack Archer
10/28/2021, 7:23 PMJack Archer
10/28/2021, 7:23 PMCharith (Cerbos)
$$
to escape the $
sign.
adminAPI:
enabled: true
adminCredentials:
username: "cerbos"
passwordHash: "$2y$10$$zoVBUHm7YJu7Uj21WeeALOTObW1MQ0IxdjYBBwiv3i2j.BVPZAZ6C"
Jack Archer
10/28/2021, 7:25 PMJack Archer
10/28/2021, 7:25 PMCharith (Cerbos)
Jack Archer
10/28/2021, 7:25 PMJack Archer
10/28/2021, 7:26 PMCharith (Cerbos)
Jack Archer
10/28/2021, 7:48 PMJack Archer
10/28/2021, 7:48 PMCharith (Cerbos)
Charith (Cerbos)
Jack Archer
10/29/2021, 3:03 PM