Skip to content

Commit

Permalink
fix: add owner registration logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nsklikas committed Dec 10, 2024
1 parent 81323ee commit 60e88ac
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
20 changes: 19 additions & 1 deletion internal/broker/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package broker

import (
"embed"
"errors"
"fmt"
"io/fs"
Expand Down Expand Up @@ -39,8 +40,21 @@ const (
AllUsersKey = "ALL"
// OwnerUserKey is the key for allowing access to the owner

Check failure on line 41 in internal/broker/config.go

View workflow job for this annotation

GitHub Actions / Go: Code sanity

Comment should end in a period (godot)
OwnerUserKey = "OWNER"

// ownerAutoregistrationConfigPath is the name of the file that will be auto-generated to register the owner

Check failure on line 44 in internal/broker/config.go

View workflow job for this annotation

GitHub Actions / Go: Code sanity

Comment should end in a period (godot)
ownerRegistrationConfigPath = "20-owner-autoregistration.conf"
ownerRegistrationConfigTemplate = "templates/20-owner-autoregistration.conf.tmpl"
)

var (
//go:embed templates/20-owner-autoregistration.conf.tmpl
ownerRegistrationConfig embed.FS
)

type templateEnv struct {
Owner string
}

type userConfig struct {
clientID string
clientSecret string
Expand All @@ -53,9 +67,13 @@ type userConfig struct {
allowedSSHSuffixes []string
}

func getDropInDir(cfgPath string) string {
return cfgPath + ".d"
}

func getDropInFiles(cfgPath string) ([]any, error) {
// Check if a .d directory exists and return the paths to the files in it.
dropInDir := cfgPath + ".d"
dropInDir := getDropInDir(cfgPath)
files, err := os.ReadDir(dropInDir)
if errors.Is(err, fs.ErrNotExist) {
return nil, nil
Expand Down
13 changes: 13 additions & 0 deletions internal/broker/templates/20-owner-autoregistration.conf.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## This file was generated automatically by the broker. DO NOT EDIT.
##
## This file registers the first authenticated user as the owner of
## this device.
##
## The 'owner' option is only considered for authentication if
## 'allowed_users' contains the 'OWNER' keyword.
##
## To register a different owner for the machine on the next
## successful authentication, delete this file.

[users]
owner = {{ .Owner }}
4 changes: 4 additions & 0 deletions internal/broker/testdata/golden/TestPersistOwner/broker.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

[oidc]
issuer = https://issuer.url.com
client_id = client_id
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## This file was generated automatically by the broker. DO NOT EDIT.
##
## This file registers the first authenticated user as the owner of
## this device.
##
## The 'owner' option is only considered for authentication if
## 'allowed_users' contains the 'OWNER' keyword.
##
## To register a different owner for the machine on the next
## successful authentication, delete this file.

[users]
owner = owner_name

0 comments on commit 60e88ac

Please sign in to comment.