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

Add changes to run clusterinterceptor as HTTPS #1333

Merged
merged 1 commit into from
May 2, 2022

Conversation

savitaashture
Copy link
Contributor

Changes

TEP: tektoncd/community#662

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes tests (if functionality changed/added)
  • Includes docs (if user facing)
  • Commit messages follow commit message best practices
  • Release notes block has been filled in or deleted (only if no user facing changes)

See the contribution guide for more details.

Release Notes

Triggers now support end to end secure connection by running ClusterInterceptor server as HTTPS 

@savitaashture savitaashture requested review from khrm and dibyom March 24, 2022 03:48
@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 24, 2022
@tekton-robot tekton-robot requested a review from vtereso March 24, 2022 03:48
@savitaashture savitaashture added kind/feature Categorizes issue or PR as related to a new feature. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 24, 2022
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/interceptors/interceptors.go 88.7% 83.6% -5.1
pkg/sink/initialization.go 50.0% 27.6% -22.4

@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 24, 2022
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/interceptors/interceptors.go 88.7% 83.6% -5.1
pkg/sink/initialization.go 50.0% 27.6% -22.4

@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/interceptors/interceptors.go 88.7% 83.6% -5.1
pkg/sink/initialization.go 50.0% 27.6% -22.4

@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/interceptors/interceptors.go 88.7% 83.6% -5.1
pkg/sink/initialization.go 50.0% 27.6% -22.4

@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/interceptors/interceptors.go 88.7% 83.6% -5.1
pkg/sink/initialization.go 50.0% 27.6% -22.4

@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/interceptors/interceptors.go 88.7% 83.6% -5.1
pkg/sink/initialization.go 50.0% 27.6% -22.4

@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/interceptors/interceptors.go 88.7% 88.1% -0.6
pkg/sink/initialization.go 50.0% 27.6% -22.4

@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/interceptors/interceptors.go 88.7% 88.1% -0.6
pkg/sink/initialization.go 50.0% 27.6% -22.4

@@ -72,8 +89,62 @@ func main() {
mux.Handle("/", service)
mux.HandleFunc("/ready", handler)

name := os.Getenv("SVC_NAME")
Copy link
Member

Choose a reason for hiding this comment

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

IMO we should give this a more explicit name than SVC name e.g. INTERCEPTOR_TLS_SECRET or something like that

@@ -65,7 +65,7 @@ metadata:
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "list", "watch"]
verbs: ["get", "list", "watch", "update"]
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should change the role to be able to update all secrets. Instead create another rule that can update the specific secret that we need

Copy link
Contributor Author

@savitaashture savitaashture Apr 11, 2022

Choose a reason for hiding this comment

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

I see tekton-triggers-core-interceptors cluster role is only used for tekton-triggers-core-interceptors deployment so i believe this is for specified one only

Let me know if this is your concern or something else

Copy link
Member

Choose a reason for hiding this comment

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

Right the concern is that this allows the core interceptor server access to update any secret in the cluster which is a bit scary. What we should do is to make sure it can only update the TLS secret for the cluster interceptor.
See the example here where the webhook role can only update the webhook-certs secret using the resourceName field: https://github.com/tektoncd/pipeline/blob/main/config/200-role.yaml#L59-L65

if svc.Port != nil {
port = *svc.Port
}
url := &apis.URL{
Scheme: "http", // TODO: Support HTTPs if caBundle is present
Scheme: "https",
Copy link
Member

Choose a reason for hiding this comment

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

hmm..we'd have to be a bit careful here...if we move this to only support https, anyone who has written a cluster interceptor will not be able use Triggers until they upgrade their code. Should we support both for a release or two?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah i see

Okay so do you mean we need to have support for both HTTP and HTTPS right/

If thats the case we need to take input from deplpyment yaml to know whether they want HTTP or HTTPS
Shall i change implementation that way ?

Copy link
Member

Choose a reason for hiding this comment

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

we discussed this in the WG - we should take the input for whether it is HTTP/HTTPS from interceptor CRD itself.

@dibyom dibyom linked an issue Apr 27, 2022 that may be closed by this pull request
createCerts = true
}

// TODO: Certification validation and rotation is pending
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dibyom will create an issue to handle it in separate PR

Copy link
Member

Choose a reason for hiding this comment

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

could you open an issue to track?

@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1alpha1/cluster_interceptor_defaults.go 100.0% N/A -100.0
pkg/interceptors/interceptors.go 88.7% 87.1% -1.6

Copy link
Member

@dibyom dibyom left a comment

Choose a reason for hiding this comment

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

Almost there - I do think we need to modify how we are creating the http clients else we will break timeouts

return nil, fmt.Errorf("unable to parse cert from %s", ic.Spec.ClientConfig.CaBundle)
}

client = &http.Client{
Copy link
Member

Choose a reason for hiding this comment

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

I think we have to update this - creating a new client here means we will ignore all of the config options that we set in the already passed in HTTP client (such as the timeout values). Creating a new HTTP client per call means we can't reuse the underlying connections so we might be limiting the number of calls from the EL to the interceptor.

I think we'd have to add in the certs in the sinker.Start function - we could pass in a clusterinterceptorlister as an arg to the sinker struct - list all the clusterinterceptors, get the caCert and add it to the certPool. and then create a httpClient with all the certs. (This does mean that if we add a new interceptor in the middle, we'd have to restart each EL.

(Ideally in the future we'd have something that listens for changes to interceptors and updates the httpClient with newCerts on the fly)

Copy link
Contributor Author

@savitaashture savitaashture Apr 29, 2022

Choose a reason for hiding this comment

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

@dibyom Yes i agree with you
It overrides previous given values

Updated code PTAL 🙏
Thank you

createCerts = true
}

// TODO: Certification validation and rotation is pending
Copy link
Member

Choose a reason for hiding this comment

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

could you open an issue to track?

log.Printf("secret %s is missing", interceptorSecretName)
return "", "", []byte{}, err
}
log.Printf("error accessing certificate secret %q: %v", interceptorSecretName, err)
Copy link
Member

Choose a reason for hiding this comment

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

can we use logger as we do in the rest of the function vs log.Printf

@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1alpha1/cluster_interceptor_defaults.go 100.0% N/A -100.0

@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1alpha1/cluster_interceptor_defaults.go 100.0% N/A -100.0

}
// write serverCert to file so that it can be passed while running https server.
// Expect WriteFile permissions to be 0600 or less (gosec)
//nolint:gosec
Copy link
Member

Choose a reason for hiding this comment

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

Hmm why do we have 0600?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if given file permission is more than 600 the its giving security issue during build

cmd/interceptors/main.go:211:11: G306: Expect WriteFile permissions to be 0600 or less (gosec)
	if err = ioutil.WriteFile(certFile, serverCert, 0644); err != nil {
	         ^

For now instead of using 644 i m using 600 and removing //nolint:gosec
Updated main.go

Thanks for pointing it out 👍 I forgot to remove it earlier

Copy link
Member

@dibyom dibyom left a comment

Choose a reason for hiding this comment

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

Just one question, else LGTM!

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 29, 2022
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1alpha1/cluster_interceptor_defaults.go 100.0% N/A -100.0

@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1alpha1/cluster_interceptor_defaults.go 100.0% N/A -100.0

@savitaashture
Copy link
Contributor Author

/test pull-tekton-triggers-build-tests

@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1alpha1/cluster_interceptor_defaults.go 100.0% N/A -100.0

@savitaashture
Copy link
Contributor Author

/test pull-tekton-triggers-integration-tests

@savitaashture
Copy link
Contributor Author

@dibyom PR is ready for final review

Thank You!!

@tekton-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dibyom

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@dibyom
Copy link
Member

dibyom commented May 2, 2022

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label May 2, 2022
@tekton-robot tekton-robot merged commit 28d7b73 into tektoncd:main May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/feature Categorizes issue or PR as related to a new feature. lgtm 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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow TLS connections between EventListener and Interceptors
3 participants