-
Notifications
You must be signed in to change notification settings - Fork 75
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
Adds webhook for Repository Validation #708
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b662fa4
Adds webhook to validate repository url
34cb5a0
Adds yamls for webhook
58ed515
Allow update to existing repository
5639a6f
e2e: delete repository in the namespace before deleting ns
22d7262
update build workflow for webhook image
7e1647b
updates release yaml script for webhook
a383c92
add e2e for repo creation and failure due to webhook validation
372bb16
Use repository lister instead of client
4ea5b59
Skip running e2e parallel
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
validation_webhook "github.com/openshift-pipelines/pipelines-as-code/pkg/webhook" | ||
"knative.dev/pkg/configmap" | ||
"knative.dev/pkg/controller" | ||
"knative.dev/pkg/injection" | ||
"knative.dev/pkg/injection/sharedmain" | ||
"knative.dev/pkg/signals" | ||
"knative.dev/pkg/webhook" | ||
"knative.dev/pkg/webhook/certificates" | ||
) | ||
|
||
func main() { | ||
ctx := signals.NewContext() | ||
|
||
serviceName := os.Getenv("WEBHOOK_SERVICE_NAME") | ||
if serviceName == "" { | ||
serviceName = "pipelines-as-code-webhook" | ||
} | ||
secretName := os.Getenv("WEBHOOK_SECRET_NAME") | ||
if secretName == "" { | ||
secretName = "pipelines-as-code-webhook-certs" | ||
} | ||
// Set up a signal context with our webhook options | ||
ctx = webhook.WithOptions(ctx, webhook.Options{ | ||
ServiceName: serviceName, | ||
Port: 8443, | ||
SecretName: secretName, | ||
}) | ||
|
||
sharedmain.WebhookMainWithConfig(ctx, "pipelines-as-code-webhook", | ||
injection.ParseAndGetRESTConfigOrDie(), | ||
certificates.NewController, | ||
newValidationAdmissionController, | ||
) | ||
} | ||
|
||
func newValidationAdmissionController(ctx context.Context, _ configmap.Watcher) *controller.Impl { | ||
return validation_webhook.NewAdmissionController(ctx, | ||
|
||
// Name of the resource webhook. | ||
"validation.pipelinesascode.tekton.dev", | ||
|
||
// The path on which to serve the webhook. | ||
"/validate", | ||
|
||
// A function that infuses the context passed to Validate/SetDefaults with custom metadata. | ||
func(ctx context.Context) context.Context { | ||
return ctx | ||
}, | ||
|
||
// Whether to disallow unknown fields. | ||
true, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# Copyright 2022 Red Hat | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: pipelines-as-code-webhook | ||
namespace: pipelines-as-code | ||
labels: | ||
app.kubernetes.io/version: "devel" | ||
app.kubernetes.io/instance: default | ||
app.kubernetes.io/part-of: pipelines-as-code | ||
--- | ||
kind: Role | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
metadata: | ||
name: pipelines-as-code-webhook-role | ||
namespace: pipelines-as-code | ||
labels: | ||
app.kubernetes.io/version: "devel" | ||
app.kubernetes.io/instance: default | ||
app.kubernetes.io/part-of: pipelines-as-code | ||
rules: | ||
- apiGroups: [""] | ||
resources: ["configmaps"] | ||
verbs: ["get", "list", "watch"] | ||
- apiGroups: [""] | ||
resources: ["secrets"] | ||
verbs: ["list", "watch"] | ||
- apiGroups: [""] | ||
resources: ["secrets"] | ||
verbs: ["get", "update"] | ||
resourceNames: ["pipelines-as-code-webhook-certs"] | ||
# The webhook daemon makes a reconciliation loop on webhook-certs. Whenever | ||
# the secret changes it updates the webhook configurations with the certificates | ||
# stored in the secret. | ||
- apiGroups: ["coordination.k8s.io"] | ||
resources: ["leases"] | ||
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"] | ||
# webhook uses leases for leader election | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: pipelines-as-code-webhook-binding | ||
namespace: pipelines-as-code | ||
labels: | ||
app.kubernetes.io/version: "devel" | ||
app.kubernetes.io/instance: default | ||
app.kubernetes.io/part-of: pipelines-as-code | ||
subjects: | ||
- kind: ServiceAccount | ||
name: pipelines-as-code-webhook | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: pipelines-as-code-webhook-role | ||
--- | ||
kind: ClusterRole | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
metadata: | ||
name: pipeline-as-code-webhook-clusterrole | ||
namespace: pipelines-as-code | ||
labels: | ||
app.kubernetes.io/version: "devel" | ||
app.kubernetes.io/instance: default | ||
app.kubernetes.io/part-of: pipelines-as-code | ||
rules: | ||
- apiGroups: ["pipelinesascode.tekton.dev"] | ||
resources: ["repositories"] | ||
verbs: ["get", "list", "watch"] | ||
# The webhook performs a reconciliation on this resource and continuously | ||
# updates configuration. | ||
- apiGroups: ["admissionregistration.k8s.io"] | ||
resources: ["validatingwebhookconfigurations"] | ||
verbs: ["list", "watch"] | ||
# When there are changes to the configs or secrets, knative updates the validating webhook config | ||
# with the updated certificates or the refreshed set of rules. | ||
- apiGroups: ["admissionregistration.k8s.io"] | ||
resources: ["validatingwebhookconfigurations"] | ||
verbs: ["get", "update", "delete"] | ||
resourceNames: ["validation.pipelinesascode.tekton.dev"] | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: pipelines-as-code-webhook-clusterbinding | ||
namespace: pipelines-as-code | ||
labels: | ||
app.kubernetes.io/version: "devel" | ||
app.kubernetes.io/instance: default | ||
app.kubernetes.io/part-of: pipelines-as-code | ||
subjects: | ||
- kind: ServiceAccount | ||
name: pipelines-as-code-webhook | ||
namespace: pipelines-as-code | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: pipeline-as-code-webhook-clusterrole |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2022 Red Hat | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: pipelines-as-code-webhook-certs | ||
namespace: pipelines-as-code | ||
labels: | ||
app.kubernetes.io/version: "devel" | ||
app.kubernetes.io/part-of: pipelines-as-code | ||
# The data is populated at install time | ||
--- | ||
apiVersion: admissionregistration.k8s.io/v1 | ||
kind: ValidatingWebhookConfiguration | ||
metadata: | ||
name: validation.pipelinesascode.tekton.dev | ||
labels: | ||
app.kubernetes.io/version: "devel" | ||
app.kubernetes.io/part-of: pipelines-as-code | ||
webhooks: | ||
- admissionReviewVersions: ["v1"] | ||
clientConfig: | ||
service: | ||
name: pipelines-as-code-webhook | ||
namespace: pipelines-as-code | ||
failurePolicy: Fail | ||
sideEffects: None | ||
name: validation.pipelinesascode.tekton.dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright 2022 Red Hat | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: pipelines-as-code-webhook | ||
namespace: pipelines-as-code | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app.kubernetes.io/name: webhook | ||
app.kubernetes.io/component: webhook | ||
app.kubernetes.io/instance: default | ||
app.kubernetes.io/part-of: pipelines-as-code | ||
template: | ||
metadata: | ||
labels: | ||
app.kubernetes.io/name: webhook | ||
app.kubernetes.io/component: webhook | ||
app.kubernetes.io/instance: default | ||
app.kubernetes.io/part-of: pipelines-as-code | ||
app.kubernetes.io/version: "devel" | ||
spec: | ||
serviceAccountName: pipelines-as-code-webhook | ||
containers: | ||
- name: pipelines-as-code-webhook | ||
image: "ko://github.com/openshift-pipelines/pipelines-as-code/cmd/pipelines-as-code-webhook" | ||
env: | ||
- name: SYSTEM_NAMESPACE | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: metadata.namespace | ||
- name: WEBHOOK_SERVICE_NAME | ||
value: pipelines-as-code-webhook | ||
- name: WEBHOOK_SECRET_NAME | ||
value: pipelines-as-code-webhook-certs | ||
- name: METRICS_DOMAIN | ||
value: tekton.dev/pipelinesascode | ||
ports: | ||
- name: https-webhook | ||
containerPort: 8443 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright 2022 Red Hat | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: pipelines-as-code-webhook | ||
namespace: pipelines-as-code | ||
labels: | ||
name: pipelines-as-code-webhook | ||
app: pipelines-as-code | ||
spec: | ||
ports: | ||
- name: https-webhook | ||
port: 443 | ||
targetPort: 8443 | ||
selector: | ||
app.kubernetes.io/name: webhook | ||
app.kubernetes.io/component: webhook | ||
app.kubernetes.io/instance: default | ||
app.kubernetes.io/part-of: pipelines-as-code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
i think there is.a way to do "matrix" in google actions for not have to copy and paste large block everytime, i guess we can do that if we have to add another image again 🙃
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.
we can use matrix but there will 4 jobs created currently we execute all in one