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

do not switch to legacy authentication system when readUser, readPass, publishUser, publishPass are present but are empty #3113

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 20 additions & 8 deletions internal/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,24 @@ func mustParseCIDR(v string) net.IPNet {
return *ne
}

func credentialIsNotEmpty(c *Credential) bool {
return c != nil && *c != ""
}

func ipNetworkIsNotEmpty(i *IPNetworks) bool {
return i != nil && len(*i) != 0
}

func anyPathHasDeprecatedCredentials(paths map[string]*OptionalPath) bool {
for _, pa := range paths {
if pa != nil {
rva := reflect.ValueOf(pa.Values).Elem()
if !rva.FieldByName("PublishUser").IsNil() || !rva.FieldByName("PublishPass").IsNil() ||
!rva.FieldByName("PublishIPs").IsNil() ||
!rva.FieldByName("ReadUser").IsNil() || !rva.FieldByName("ReadPass").IsNil() ||
!rva.FieldByName("ReadIPs").IsNil() {
if credentialIsNotEmpty(rva.FieldByName("PublishUser").Interface().(*Credential)) ||
credentialIsNotEmpty(rva.FieldByName("PublishPass").Interface().(*Credential)) ||
ipNetworkIsNotEmpty(rva.FieldByName("PublishIPs").Interface().(*IPNetworks)) ||
credentialIsNotEmpty(rva.FieldByName("ReadUser").Interface().(*Credential)) ||
credentialIsNotEmpty(rva.FieldByName("ReadPass").Interface().(*Credential)) ||
ipNetworkIsNotEmpty(rva.FieldByName("ReadIPs").Interface().(*IPNetworks)) {
return true
}
}
Expand Down Expand Up @@ -460,10 +470,12 @@ func (conf *Conf) Validate() error {
return fmt.Errorf("'authJWTJWKS' must be a HTTP URL")
}
deprecatedCredentialsMode := false
if conf.PathDefaults.PublishUser != nil || conf.PathDefaults.PublishPass != nil ||
conf.PathDefaults.PublishIPs != nil ||
conf.PathDefaults.ReadUser != nil || conf.PathDefaults.ReadPass != nil ||
conf.PathDefaults.ReadIPs != nil ||
if credentialIsNotEmpty(conf.PathDefaults.PublishUser) ||
credentialIsNotEmpty(conf.PathDefaults.PublishPass) ||
ipNetworkIsNotEmpty(conf.PathDefaults.PublishIPs) ||
credentialIsNotEmpty(conf.PathDefaults.ReadUser) ||
credentialIsNotEmpty(conf.PathDefaults.ReadPass) ||
ipNetworkIsNotEmpty(conf.PathDefaults.ReadIPs) ||
anyPathHasDeprecatedCredentials(conf.OptionalPaths) {
conf.AuthInternalUsers = []AuthInternalUser{
{
Expand Down
12 changes: 6 additions & 6 deletions internal/conf/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,17 +383,17 @@
if deprecatedCredentialsMode {
func() {
var user Credential = "any"
if pconf.PublishUser != nil {
if credentialIsNotEmpty(pconf.PublishUser) {

Check warning on line 386 in internal/conf/path.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/path.go#L386

Added line #L386 was not covered by tests
user = *pconf.PublishUser
}

var pass Credential
if pconf.PublishPass != nil {
if credentialIsNotEmpty(pconf.PublishPass) {

Check warning on line 391 in internal/conf/path.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/path.go#L391

Added line #L391 was not covered by tests
pass = *pconf.PublishPass
}

ips := IPNetworks{mustParseCIDR("0.0.0.0/0")}
if pconf.PublishIPs != nil {
if ipNetworkIsNotEmpty(pconf.PublishIPs) {

Check warning on line 396 in internal/conf/path.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/path.go#L396

Added line #L396 was not covered by tests
ips = *pconf.PublishIPs
}

Expand All @@ -415,17 +415,17 @@

func() {
var user Credential = "any"
if pconf.ReadUser != nil {
if credentialIsNotEmpty(pconf.ReadUser) {

Check warning on line 418 in internal/conf/path.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/path.go#L418

Added line #L418 was not covered by tests
user = *pconf.ReadUser
}

var pass Credential
if pconf.ReadPass != nil {
if credentialIsNotEmpty(pconf.ReadPass) {

Check warning on line 423 in internal/conf/path.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/path.go#L423

Added line #L423 was not covered by tests
pass = *pconf.ReadPass
}

ips := IPNetworks{mustParseCIDR("0.0.0.0/0")}
if pconf.ReadIPs != nil {
if ipNetworkIsNotEmpty(pconf.ReadIPs) {

Check warning on line 428 in internal/conf/path.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/path.go#L428

Added line #L428 was not covered by tests
ips = *pconf.ReadIPs
}

Expand Down
Loading