Skip to content

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

Merged

Conversation

pleshakov
Copy link
Contributor

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.

@pleshakov pleshakov added the enhancement Pull requests for new features/feature enhancements label Apr 5, 2021
@github-actions github-actions bot added the documentation Pull requests/issues for documentation label Apr 5, 2021
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

is this correct?

@@ -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)
Copy link
Contributor

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?

Copy link
Contributor Author

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

@pleshakov pleshakov requested a review from soneillf5 April 6, 2021 22:09
return false, nil
}

return statErr == nil, statErr
Copy link
Contributor

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

Copy link
Contributor Author

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.
@pleshakov pleshakov force-pushed the feature/use-ssl-reject-handshake-in-default-server branch from 8a7ece9 to 2d9a279 Compare April 7, 2021 18:50
@pleshakov pleshakov requested a review from soneillf5 April 7, 2021 18:50
@pleshakov pleshakov merged commit 3c10b91 into master Apr 8, 2021
@pleshakov pleshakov deleted the feature/use-ssl-reject-handshake-in-default-server branch April 8, 2021 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Pull requests/issues for documentation enhancement Pull requests for new features/feature enhancements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants