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

specify custom ca file to verify the keystone server #35488

Merged
merged 1 commit into from
Nov 8, 2016

Conversation

dixudx
Copy link
Member

@dixudx dixudx commented Oct 25, 2016

What this PR does / why we need it:

Sometimes the keystone server's certificate is self-signed, mainly used for internal development, testing and etc.

For this kind of ca, we need a way to verify the keystone server.

Otherwise, below error will occur.

x509: certificate signed by unknown authority

This patch provide a way to pass in a ca file to verify the keystone server when starting kube-apiserver.

Which issue this PR fixes : fixes #22695, #24984

Special notes for your reviewer:

Release note:


This change is Reviewable

@k8s-ci-robot
Copy link
Contributor

Can a kubernetes member verify that this patch is reasonable to test? If so, please reply with "@k8s-bot ok to test" on its own line.

Regular contributors should join the org to skip this step.

@@ -375,6 +376,11 @@ func (s *ServerRunOptions) AddUniversalFlags(fs *pflag.FlagSet) {
fs.StringVar(&s.KeystoneURL, "experimental-keystone-url", s.KeystoneURL,
"If passed, activates the keystone authentication plugin.")

fs.StringVar(&s.KeystoneCAFile, "experimental-keystone-ca-file", s.KeystoneCAFile, ""+
Copy link
Member

Choose a reason for hiding this comment

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

Use the OIDCCAFile flag description as a starting point instead

Copy link
Member Author

Choose a reason for hiding this comment

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

Already fix this.

@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. release-note-label-needed labels Oct 25, 2016
// NewKeystoneAuthenticator returns a password authenticator that validates credentials using openstack keystone
func NewKeystoneAuthenticator(authURL string) (*KeystoneAuthenticator, error) {
func NewKeystoneAuthenticator(authURL string, caFile string) (*KeystoneAuthenticator, error) {
if !strings.HasPrefix(authURL, "https") {
return nil, errors.New("Auth URL should be secure and start with https")
}
if authURL == "" {
return nil, errors.New("Auth URL is empty")
}

Copy link
Member

Choose a reason for hiding this comment

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

Load the cert pool from the given file here if cafile is set, rather than loading it for every request

return nil, err
}

config := &tls.Config{}
Copy link
Member

Choose a reason for hiding this comment

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

Skip this whole block if the capool is nil?

Copy link
Member Author

Choose a reason for hiding this comment

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

certutil.NewPool will return an error if the file could not be read, a certificate could not be parsed, or if the file does not contain any certificates.

So I think it is okay to remain the codes here unchanged.

Copy link
Member

Choose a reason for hiding this comment

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

I mean, leave client.HTTPClient.Transport untouched unless we want to customize the ca pool

config.RootCAs = roots
}
client.HTTPClient.Transport = &http.Transport{TLSClientConfig: config, }

Copy link
Member

Choose a reason for hiding this comment

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

return openstack.Authenticate(…)

Copy link
Member Author

Choose a reason for hiding this comment

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

I did not get the actual use of this return.

Copy link
Member

Choose a reason for hiding this comment

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

the function already returns client, err, so just return the result directly, instead of if err != nil ...

}
config.RootCAs = roots
}
client.HTTPClient.Transport = &http.Transport{TLSClientConfig: config, }
Copy link
Member

Choose a reason for hiding this comment

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

Needs gofmt

Copy link
Member

Choose a reason for hiding this comment

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

is this equivalent to the transport set up by default by openstack.AuthenticatedClient (with respect to proxy settings, dial settings, timeouts, etc)?

Copy link
Member Author

Choose a reason for hiding this comment

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

The client created by default openstack.AuthenticatedClient is *gophercloud.ProviderClient.

    return &gophercloud.ProviderClient{
        IdentityBase:     base,
        IdentityEndpoint: "",
    }, nil

The default HTTPClient.Transport is nil, and DefaultTransport is used instead.

var DefaultTransport RoundTripper = &Transport{
    Proxy: ProxyFromEnvironment,
    Dial: (&net.Dialer{
        Timeout:   30 * time.Second,
        KeepAlive: 30 * time.Second,
    }).Dial,
    TLSHandshakeTimeout:   10 * time.Second,
    ExpectContinueTimeout: 1 * time.Second,
}

The client.HTTPClient.Transport I used here is quite a new Transport with only TLSClientConfig configured.

Do you suggest that we should merge these two together ?

Copy link
Member

Choose a reason for hiding this comment

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

util/net#SetOldTransportDefaults(&http.Transport{TLSClientConfig: config}) will set the default dialer, proxy, and timeouts

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 27, 2016
@k8s-github-robot k8s-github-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Oct 27, 2016
@k8s-github-robot k8s-github-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Oct 27, 2016
@k8s-github-robot k8s-github-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Oct 30, 2016
@k8s-github-robot k8s-github-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Nov 1, 2016
roots, err := certutil.NewPool(caFile)
if err != nil {
return nil, err
}
Copy link
Member

Choose a reason for hiding this comment

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

build the transport once here and save it

}
config := &tls.Config{}
config.RootCAs = roots
return &KeystoneAuthenticator{authURL, config, caFile}, nil
Copy link
Member

Choose a reason for hiding this comment

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

no need to store config or caFile in the struct, just the custom transport

return nil, err
}

if keystoneAuthenticator.caFile != "" {
Copy link
Member

Choose a reason for hiding this comment

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

if keystoneAuthenticator.transport != nil {
  client.HTTPClient.Transport = keystoneAuthenticator.transport
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed this in the new commit. Thanks.

@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 3, 2016
Copy link
Member

@liggitt liggitt left a comment

Choose a reason for hiding this comment

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

squash and rebase as well

)

// KeystoneAuthenticator contacts openstack keystone to validate user's credentials passed in the request.
// The keystone endpoint is passed during apiserver startup
type KeystoneAuthenticator struct {
authURL string
authURL string
transport *http.Transport
Copy link
Member

Choose a reason for hiding this comment

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

http.RoundTripper

}

if keystoneAuthenticator.transport != "" {
client.HTTPClient.Transport = netutil.SetOldTransportDefaults(keystoneAuthenticator.transport)
Copy link
Member

Choose a reason for hiding this comment

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

client.HTTPClient.Transport = keystoneAuthenticator.transport

}
config := &tls.Config{}
config.RootCAs = roots
transport := &http.Transport{TLSClientConfig: config}
Copy link
Member

Choose a reason for hiding this comment

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

netutil.SetOldTransportDefaults(&http.Transport{TLSClientConfig: config})

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. Fixed.

@liggitt liggitt added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-label-needed labels Nov 3, 2016
@k8s-ci-robot
Copy link
Contributor

Jenkins unit/integration failed for commit f00026bcf202bc2b50b26081b4ba707492f4f48f. Full PR test history.

The magic incantation to run this job again is @k8s-bot unit test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 3, 2016
@@ -189,6 +189,8 @@ experimental-allowed-unsafe-sysctls
experimental-bootstrap-kubeconfig
experimental-keystone-url
experimental-mounter-path
experimental-mounter-rootfs-path
Copy link
Member

Choose a reason for hiding this comment

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

this looks unrelated... might need to rebase or remove this

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know where it comes from. Seems rebase from previous commits. I did not add this. Quite weird.

Already removed this. Fixed.

@k8s-ci-robot
Copy link
Contributor

Jenkins verification failed for commit f00026bcf202bc2b50b26081b4ba707492f4f48f. Full PR test history.

The magic incantation to run this job again is @k8s-bot verify test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@liggitt
Copy link
Member

liggitt commented Nov 3, 2016

also needs

I1103 08:44:17.892] Run ./hack/update-bazel.sh
I1103 08:44:17.893] FAILED   hack/make-rules/../../hack/verify-bazel.sh 22s

@dixudx
Copy link
Member Author

dixudx commented Nov 3, 2016

@k8s-bot verify test this

1 similar comment
@dixudx
Copy link
Member Author

dixudx commented Nov 4, 2016

@k8s-bot verify test this

@dixudx
Copy link
Member Author

dixudx commented Nov 4, 2016

Hi @liggitt I retest this patch on my local env. All works well.

And the corresponding doc PR has also been submitted.

Need lgtm label again. Thanks.

@liggitt liggitt added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 4, 2016
@saad-ali
Copy link
Member

saad-ali commented Nov 8, 2016

Release-czar approved post-code freeze merge--This was LGTMed and in the merge-queue at code freeze time for 1.5. Adding 1.5 milestone to let it gets merged after code freeze.

@saad-ali saad-ali added this to the v1.5 milestone Nov 8, 2016
@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit 860cae0 into kubernetes:master Nov 8, 2016
k8s-github-robot pushed a commit that referenced this pull request Feb 26, 2017
Automatic merge from submit-queue (batch tested with PRs 40932, 41896, 41815, 41309, 41628)

Add custom CA file to openstack cloud provider config

**What this PR does / why we need it**: Adds ability to specify custom CA bundle file to verify OpenStack endpoint against. Useful in tests and PoC deployments. Similar to what #35488 did for authentication.  


**Which issue this PR fixes**: None

**Special notes for your reviewer**: Based on #35488 which added support for custom CA file for authentication.

**Release note**:
dims pushed a commit to dims/openstack-cloud-controller-manager that referenced this pull request Mar 24, 2017
Automatic merge from submit-queue (batch tested with PRs 40932, 41896, 41815, 41309, 41628)

Add custom CA file to openstack cloud provider config

**What this PR does / why we need it**: Adds ability to specify custom CA bundle file to verify OpenStack endpoint against. Useful in tests and PoC deployments. Similar to what kubernetes/kubernetes#35488 did for authentication.  


**Which issue this PR fixes**: None

**Special notes for your reviewer**: Based on kubernetes/kubernetes#35488 which added support for custom CA file for authentication.

**Release note**:
jrperritt pushed a commit to jrperritt/osccm that referenced this pull request Jul 12, 2017
Automatic merge from submit-queue (batch tested with PRs 40932, 41896, 41815, 41309, 41628)

Add custom CA file to openstack cloud provider config

**What this PR does / why we need it**: Adds ability to specify custom CA bundle file to verify OpenStack endpoint against. Useful in tests and PoC deployments. Similar to what kubernetes/kubernetes#35488 did for authentication.  


**Which issue this PR fixes**: None

**Special notes for your reviewer**: Based on kubernetes/kubernetes#35488 which added support for custom CA file for authentication.

**Release note**:
dims pushed a commit to dims/openstack-cloud-controller-manager that referenced this pull request Sep 6, 2017
Automatic merge from submit-queue (batch tested with PRs 40932, 41896, 41815, 41309, 41628)

Add custom CA file to openstack cloud provider config

**What this PR does / why we need it**: Adds ability to specify custom CA bundle file to verify OpenStack endpoint against. Useful in tests and PoC deployments. Similar to what kubernetes/kubernetes#35488 did for authentication.  


**Which issue this PR fixes**: None

**Special notes for your reviewer**: Based on kubernetes/kubernetes#35488 which added support for custom CA file for authentication.

**Release note**:
@dixudx dixudx deleted the keystone-ca-cert branch September 9, 2017 14:11
dims pushed a commit to dims/openstack-cloud-controller-manager that referenced this pull request Jan 13, 2018
Automatic merge from submit-queue (batch tested with PRs 40932, 41896, 41815, 41309, 41628)

Add custom CA file to openstack cloud provider config

**What this PR does / why we need it**: Adds ability to specify custom CA bundle file to verify OpenStack endpoint against. Useful in tests and PoC deployments. Similar to what kubernetes/kubernetes#35488 did for authentication.  


**Which issue this PR fixes**: None

**Special notes for your reviewer**: Based on kubernetes/kubernetes#35488 which added support for custom CA file for authentication.

**Release note**:
calebamiles pushed a commit to kubernetes/cloud-provider-openstack that referenced this pull request Mar 21, 2018
Automatic merge from submit-queue (batch tested with PRs 40932, 41896, 41815, 41309, 41628)

Add custom CA file to openstack cloud provider config

**What this PR does / why we need it**: Adds ability to specify custom CA bundle file to verify OpenStack endpoint against. Useful in tests and PoC deployments. Similar to what kubernetes/kubernetes#35488 did for authentication.  


**Which issue this PR fixes**: None

**Special notes for your reviewer**: Based on kubernetes/kubernetes#35488 which added support for custom CA file for authentication.

**Release note**:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optional support for unsecure keystone API URL
6 participants