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

Webhook sec #147

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions Parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,11 @@ The sub directory where the pom.xml is located and where the `mvn install` shoul
contextDir: /
```

#### webSourcesParams
Those are additional parameter of webSourcesParams to describe how to build the application images.

##### artifactDir (webSourcesParams)
The artifactDir is a parameter of the SourceBuildStrategy the operator is using. It is the directory where maven places the war it creates for the webapp.
The contents of artifactDir is copied in the webapps directory of the image used to deploy the application /opt/jws-5.x/tomcat/webapps. The default value is target.
#### webhookSecrets
Secret names for triggering a build through webhook.

##### mavenMirrorUrl (webSourcesParams)
The mavenMirrorUrl is a parameter of the SourceBuildStrategy the operator is using. It is the maven proxy URL that maven will use to build the webapp. It is required if the cluster doesn't have access to the Internet.

##### genericWebhookSecret (webSourcesParams)
This explains how to use a secret for a generic webhook to trigger a build.
##### Generic (webhookSecrets)
Secret name for triggering a build.

1 - Create a base64 secret string:
Base64 encoded string secret can be created by base64 tool. In the following example, the secret "qwerty" is used
Expand All @@ -204,7 +197,8 @@ secret/jws-secret created

So here we use:
```
genericWebhookSecret: jws-secret
webhookSecrets:
generic: jws-secret
```

To test it:
Expand Down Expand Up @@ -249,12 +243,28 @@ The build is triggered.

Go to Setting+Webhooks+Add webhook in your github project and add the URL in the Payload URL, set Content type: application/json, Disable SSL verification if needed and click Add webhook. See https://docs.openshift.com/container-platform/4.6/builds/triggering-builds-build-hooks.html for more details.

##### githubWebhookSecret (webSourcesParams)
That is a web hook specific to GitHub, it works like `genericWebhookSecret`
##### Github (webhookSecrets)
Secret name for triggering a build from Github.

##### Gitlab (webhookSecrets)
Secret name for triggering a build from Gitlab.

#### webSourcesParams
Those are additional parameter of webSourcesParams to describe how to build the application images.

##### artifactDir (webSourcesParams)
The artifactDir is a parameter of the SourceBuildStrategy the operator is using. It is the directory where maven places the war it creates for the webapp.
The contents of artifactDir is copied in the webapps directory of the image used to deploy the application /opt/jws-5.x/tomcat/webapps. The default value is target.

##### mavenMirrorUrl (webSourcesParams)
The mavenMirrorUrl is a parameter of the SourceBuildStrategy the operator is using. It is the maven proxy URL that maven will use to build the webapp. It is required if the cluster doesn't have access to the Internet.

##### (Deprecated) genericWebhookSecret (webSourcesParams)
Web hook secret string

##### (Deprecated) githubWebhookSecret (webSourcesParams)
That is a web hook secret string specific to GitHub, it works like `genericWebhookSecret`

```
githubWebhookSecret: jws-secret
```
Note that it is not possible to test the Github webhook by hands: The playload is generated by github and it is NOT empty.


Expand Down
15 changes: 13 additions & 2 deletions api/v1alpha1/webserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ type WebSourcesSpec struct {
ContextDir string `json:"contextDir,omitempty"`
// (Optional) Sources related parameters
WebSourcesParams *WebSourcesParamsSpec `json:"webSourcesParams,omitempty"`
// Webhook secrets configuration
WebhookSecrets *WebhookSecrets `json:"webhookSecrets,omitempty"`
}

// (Optional) Sources related parameters
Expand All @@ -120,12 +122,21 @@ type WebSourcesParamsSpec struct {
MavenMirrorURL string `json:"mavenMirrorUrl,omitempty"`
// Directory where the jar/war is created
ArtifactDir string `json:"artifactDir,omitempty"`
// Secret for a generic web hook
// (Deprecated - Use WebhookSecrets instead) Secret string for a generic web hook
GenericWebhookSecret string `json:"genericWebhookSecret,omitempty"`
// Secret for a Github web hook
// (Deprecated - Use WebhookSecrets instead) Secret string for a Github web hook
GithubWebhookSecret string `json:"githubWebhookSecret,omitempty"`
}

type WebhookSecrets struct {
// Secret for generic webhook
Generic string `json:"generic,omitempty"`
// Secret for Github webhook
Github string `json:"github,omitempty"`
// Secret for Gitlab webhook
Gitlab string `json:"gitlab,omitempty"`
}

type WebServerHealthCheckSpec struct {
// String for the pod readiness health check logic
ServerReadinessScript string `json:"serverReadinessScript"`
Expand Down
20 changes: 20 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions config/crd/bases/web.servers.org_webservers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -477,15 +477,30 @@ spec:
description: Directory where the jar/war is created
type: string
genericWebhookSecret:
description: Secret for a generic web hook
description: (Deprecated - Use WebhookSecrets instead)
Secret string for a generic web hook
type: string
githubWebhookSecret:
description: Secret for a Github web hook
description: (Deprecated - Use WebhookSecrets instead)
Secret string for a Github web hook
type: string
mavenMirrorUrl:
description: URL to a maven repository
type: string
type: object
webhookSecrets:
description: Webhook secrets configuration
properties:
generic:
description: Secret for generic webhook
type: string
github:
description: Secret for Github webhook
type: string
gitlab:
description: Secret for Gitlab webhook
type: string
type: object
required:
- sourceRepositoryUrl
type: object
Expand Down
40 changes: 34 additions & 6 deletions controllers/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,24 +523,52 @@ func (r *WebServerReconciler) generateBuildTriggerPolicy(webServer *webserversv1
sources := webServer.Spec.WebImageStream.WebSources
if sources != nil {
params := sources.WebSourcesParams
if params != nil {
if params.GithubWebhookSecret != "" {

if sources.WebhookSecrets != nil {
if sources.WebhookSecrets.Generic != "" {
buildTriggerPolicies = append(buildTriggerPolicies, buildv1.BuildTriggerPolicy{
Type: "Generic",
GenericWebHook: &buildv1.WebHookTrigger{
SecretReference: &buildv1.SecretLocalReference{
Name: sources.WebhookSecrets.Generic,
},
},
})
}
if sources.WebhookSecrets.Github != "" {
buildTriggerPolicies = append(buildTriggerPolicies, buildv1.BuildTriggerPolicy{
Type: "GitHub",
GitHubWebHook: &buildv1.WebHookTrigger{
SecretReference: &buildv1.SecretLocalReference{
Name: params.GithubWebhookSecret,
Name: sources.WebhookSecrets.Github,
},
},
})
}
if sources.WebhookSecrets.Gitlab != "" {
buildTriggerPolicies = append(buildTriggerPolicies, buildv1.BuildTriggerPolicy{
Type: "GitLab",
GitLabWebHook: &buildv1.WebHookTrigger{
SecretReference: &buildv1.SecretLocalReference{
Name: sources.WebhookSecrets.Gitlab,
},
},
})
}
} else if params != nil {
if params.GithubWebhookSecret != "" {
buildTriggerPolicies = append(buildTriggerPolicies, buildv1.BuildTriggerPolicy{
Type: "GitHub",
GitHubWebHook: &buildv1.WebHookTrigger{
Secret: params.GithubWebhookSecret,
},
})
}
if params.GenericWebhookSecret != "" {
buildTriggerPolicies = append(buildTriggerPolicies, buildv1.BuildTriggerPolicy{
Type: "Generic",
GenericWebHook: &buildv1.WebHookTrigger{
SecretReference: &buildv1.SecretLocalReference{
Name: params.GenericWebhookSecret,
},
Secret: params.GenericWebhookSecret,
},
})
}
Expand Down