Skip to content

Commit

Permalink
Support a driver debug user
Browse files Browse the repository at this point in the history
This should make debugging drivers easier.
  • Loading branch information
amrc-benmorrow committed Nov 28, 2024
1 parent 31d2c15 commit c56b8bc
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 15 deletions.
17 changes: 14 additions & 3 deletions acs-edge/lib/driverBroker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface ACL {
export class DriverBroker extends EventEmitter {
broker: Aedes
passwords: string
debugUser: string | undefined
acl: Map<string, ACL>
hostname: string
port: number
Expand All @@ -44,6 +45,7 @@ export class DriverBroker extends EventEmitter {
: 1883;

this.passwords = env.EDGE_PASSWORDS;
this.debugUser = env.EDGE_DEBUG_USER;

this.broker = new Aedes();
this.acl = new Map();
Expand Down Expand Up @@ -81,17 +83,26 @@ export class DriverBroker extends EventEmitter {

const fail = (f, ...a) => { log(f, ...a); callback(null, false); };

if (id != username)
return fail("Invalid client-id %s for %s", id, username);
if (!password)
return fail("No password for %s", username);
const expect = await fs.readFile(`${this.passwords}/${username}`)
.catch(e => null);
if (!expect)
return fail("Unexpected driver %s", username);
return fail("Unknown user %s", username);
if (expect.compare(password) != 0)
return fail("Bad password for %s", username);

if (username == this.debugUser) {
this.acl.set(id, {
publish: /./,
subscribe: /./,
});
return callback(null, true);
}

if (id != username)
return fail("Invalid client-id %s for %s", id, username);

this.acl.set(id, {
publish: new RegExp(
`^${prefix}/${id}/(?:status|data/\\w+|err/\\w+)$`),
Expand Down
16 changes: 4 additions & 12 deletions edge-helm-charts/charts/edge-agent/templates/edge-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ spec:
{{- end }}
- name: EDGE_PASSWORDS
value: "/usr/app/driver-passwords"
{{- if .Values.driverDebugUser }}
- name: EDGE_DEBUG_USER
value: "{{ .Values.driverDebugUser }}"
{{- end }}
resources:
limits:
memory: {{ .Values.limits.memory | quote }}
Expand Down Expand Up @@ -128,15 +132,3 @@ spec:
edgeAgent: true
secrets:
- edge-agent-sensitive-information-{{ .Values.uuid }}
{{ range $name, $image := .Values.drivers }}
---
apiVersion: factoryplus.app.amrc.co.uk/v1
kind: LocalSecret
metadata:
namespace: {{ $.Release.Namespace }}
name: "driver-passwords.{{ $k8sname }}.{{ $name | lower }}"
spec:
format: Password
secret: "driver-passwords.{{ $k8sname }}"
key: "{{ $name }}"
{{- end }}
25 changes: 25 additions & 0 deletions edge-helm-charts/charts/edge-agent/templates/local-secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{- $k8sname := include "edge-agent.k8sname" . }}
{{ range $name, $image := .Values.drivers }}
---
apiVersion: factoryplus.app.amrc.co.uk/v1
kind: LocalSecret
metadata:
namespace: {{ $.Release.Namespace }}
name: "driver-passwords.{{ $k8sname }}.{{ $name | lower }}"
spec:
format: Password
secret: "driver-passwords.{{ $k8sname }}"
key: "{{ $name }}"
{{- end }}
{{- if .Values.driverDebugUser }}
---
apiVersion: factoryplus.app.amrc.co.uk/v1
kind: LocalSecret
metadata:
namespace: {{ $.Release.Namespace }}
name: "driver-passwords.{{ $k8sname }}.{{ .Values.driverDebugUser | lower }}"
spec:
format: Password
secret: "driver-passwords.{{ $k8sname }}"
key: "{{ .Values.driverDebugUser }}"
{{- end }}
2 changes: 2 additions & 0 deletions edge-helm-charts/charts/edge-agent/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ drivers: {}

# Make the driver interface available externally.
#externalIPs: []
# Create a privileged account on the driver broker.
#driverDebugUser: admin
debug: false
verbosity: ALL,!token,!service,!sparkplug
poll_int: 10
Expand Down

0 comments on commit c56b8bc

Please sign in to comment.