Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIXED] Support multiple trusted operators using a config file #5896

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions server/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,22 @@ func (o *Options) processConfigFileLine(k string, v any, errors *[]error, warnin
opFiles = append(opFiles, v)
case []string:
opFiles = append(opFiles, v...)
case []any:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could have a look at the helper parseStringArray(). That could simplify the case "operator" a bit, I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jarema Do you want to look at using that helper or are we good as is?

for _, t := range v {
if token, ok := t.(token); ok {
if v, ok := token.Value().(string); ok {
opFiles = append(opFiles, v)
continue
derekcollison marked this conversation as resolved.
Show resolved Hide resolved
} else {
err := &configErr{tk, fmt.Sprintf("error parsing operators: unsupported type %T where string is expected", token)}
*errors = append(*errors, err)
}
} else {
err := &configErr{tk, fmt.Sprintf("error parsing operators: unsupported type %T", t)}
*errors = append(*errors, err)
}
break
}
default:
err := &configErr{tk, fmt.Sprintf("error parsing operators: unsupported type %T", v)}
*errors = append(*errors, err)
Expand Down
26 changes: 26 additions & 0 deletions server/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2932,6 +2932,32 @@ func TestReadOperatorJWT(t *testing.T) {
}
}

const operatorJwtList = `
listen: "127.0.0.1:-1"
system_account = SYSACC
operator: [
eyJ0eXAiOiJqd3QiLCJhbGciOiJlZDI1NTE5In0.eyJqdGkiOiJJVEdJNjNCUUszM1VNN1p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R0Q0Q083SjJMMlVJWk81U0dXIl0sInN5c3RlbV9hY2NvdW50IjoiQUNRVFdWR1NHSFlWWTNSNkQyV01PM1Y2TFYyTUdLNUI3RzQ3RTQzQkhKQjZGUVZZN0VITlRNTUciLCJ0eXBlIjoib3BlcmF0b3IiLCJ2ZXJzaW9uIjoyfX0.8kUmC6CwGLTJSs1zj_blsMpP5b6n2jZhZFNvMPXvJlRyyR5ZbCsxJ442BimaxaiosS8T-IFcZAIphtiOcqhRCg
]
`

func TestReadMultipleOperatorJWT(t *testing.T) {
confFileName := createConfFile(t, []byte(operatorJwtList))
opts, err := ProcessConfigFile(confFileName)
if err != nil {
t.Fatalf("Received unexpected error %s", err)
}

require_True(t, len(opts.TrustedOperators) == 2)
derekcollison marked this conversation as resolved.
Show resolved Hide resolved
require_True(t, opts.TrustedOperators[0].Name == "OP")
require_True(t, opts.TrustedOperators[1].Name == "op2")
require_True(t, opts.TrustedOperators[0].SystemAccount == "ADZ547B24WHPLWOK7TMLNBSA7FQFXR6UM2NZ4HHNIB7RDFVZQFOZ4GQQ")
require_True(t, opts.TrustedOperators[1].SystemAccount == "ACQTWVGSGHYVY3R6D2WMO3V6LV2MGK5B7G47E43BHJB6FQVY7EHNTMMG")
// check if system account precedence is correct
require_True(t, opts.SystemAccount == "SYSACC")

}

// using memory resolver so this test does not have to start the memory resolver
const operatorJwtWithSysAccAndMemResolver = `
listen: "127.0.0.1:-1"
Expand Down
Loading