-
Notifications
You must be signed in to change notification settings - Fork 2k
Don't require default server TLS secret #1512
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
Don't require default server TLS secret #1512
Conversation
cmd/nginx-ingress/main.go
Outdated
glog.Fatalf("A TLS cert and key for the default server is not found") | ||
sslRejectHandshake = true | ||
} else { | ||
glog.Fatalf("Error reading the default server TLS cert and key from %s: %v", configs.DefaultServerSecretPath, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this correct?
cmd/nginx-ingress/main.go
Outdated
@@ -440,9 +443,11 @@ func main() { | |||
bytes := configs.GenerateCertAndKeyFileContent(secret) | |||
nginxManager.CreateSecret(configs.DefaultServerSecretName, bytes, nginx.TLSSecretFileMode) | |||
} else { | |||
_, err = os.Stat("/etc/nginx/secrets/default") | |||
_, err = os.Stat(configs.DefaultServerSecretPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we write a unit test for this logic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea 👍 there was a bug
cmd/nginx-ingress/main.go
Outdated
return false, nil | ||
} | ||
|
||
return statErr == nil, statErr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the additional comments, I don't want to be too harsh, but this doesn't look correct yet.
if os.IsNotExist() -> is true then the file doesn't exist, however you're returning (statErr == nil), shouldn't that just be return true, statErr
? In which case the code becomes:
if os.IsNotExist(statErr) {
return false, nil
}
return true, statErr
which simplifies to:
return os.IsNotExist(statErr), statErr
I don't really understand this function, it appears to be just wrapping os.IsNotExist.
In terms of idiomatic error handling in Go, I think the usual practice is something like:
if os.IsTimeout(err) {
...
}
if os.IsNotExist(err) {
...
}
...
// handle valid case
return value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved offline
If the default server TLS secret is not configured via -default-server-tls-secret cli arg or it is not present on the filesystem at /etc/nginx/secrets/default, the Ingress Controller will configure NGINX to reject TLS connections to the default server. Note: The default server is used in NGINX configuration to handle HTTP and HTTPS request to hosts that are not configured by any Ingress, VirtualServer or TransportServer resources. The default server simply returns 404 responses.
8a7ece9
to
2d9a279
Compare
Proposed changes
If the default server TLS secret is not configured via -default-server-tls-secret cli arg or it is not present on the filesystem at /etc/nginx/secrets/default, the Ingress Controller will configure NGINX to reject TLS connections to the default server.
Note: The default server is used in NGINX configuration to handle HTTP and HTTPS request to hosts that are not configured by any Ingress, VirtualServer or TransportServer resources. The default server simply returns 404 responses.
Also note: because currently handling missing/invalid TLS secret relies on the default server TLS secret being present on the file system, this PR #1500 (which changes the handling) needs to be merged first.