|
| 1 | +--- |
| 2 | +title: Day 2 - Expand Capabilities |
| 3 | +hide_title: true |
| 4 | +toc_max_heading_level: 4 |
| 5 | +--- |
| 6 | + |
| 7 | +import Tabs from "@theme/Tabs"; |
| 8 | +import TabItem from "@theme/TabItem"; |
| 9 | +import TierLabel from "@site/docs/_components/TierLabel"; |
| 10 | +import AlphaWarning from "../../_components/_alpha_warning.mdx"; |
| 11 | +import CurlCodeBlock from "../../_components/CurlCodeBlock"; |
| 12 | +import oauthBitbucket from '/img/oauth-bitbucket.png'; |
| 13 | +import oauthAzureDevOps from '/img/oauth-azure-devops.png'; |
| 14 | +import oauthAzureDevOpsSuccess from '/img/oauth-azure-devops-success.png'; |
| 15 | + |
| 16 | +# Day 2 - Expand Capabilities |
| 17 | + |
| 18 | +:::info What to expect |
| 19 | +You are a Platform Engineer onboarded to Weave GitOps Enterprise to enable certain Platform Vertical like |
| 20 | +Cluster Management. |
| 21 | + |
| 22 | +Use this guide to help you to add the capabilities with confidence. |
| 23 | +::: |
| 24 | + |
| 25 | +## Enable Write Access to Git |
| 26 | + |
| 27 | +Weave GitOps Enterprise creates pull requests for adding resources. To do this, it needs to be able to write to the Git repository. |
| 28 | +Here we provide guidance for GitHub, GitLab, BitBucket Server, and Azure DevOps. |
| 29 | + |
| 30 | +<Tabs groupId="git-provider" default> |
| 31 | +<TabItem value="github" label="GitHub"> |
| 32 | +GitHub requires no additional configuration for OAuth git access |
| 33 | +</TabItem> |
| 34 | +<TabItem value="gitlab" label="GitLab"> |
| 35 | + |
| 36 | +Create a GitLab OAuth application that will request `api` permissions to create pull requests on your behalf. |
| 37 | + |
| 38 | +Follow the [GitLab docs](https://docs.gitlab.com/ee/integration/oauth_provider.html). |
| 39 | + |
| 40 | +The application should have at least these scopes: |
| 41 | + |
| 42 | +- `api` |
| 43 | +- `openid` |
| 44 | +- `email` |
| 45 | +- `profile` |
| 46 | + |
| 47 | +Add callback URLs to the application for each address the UI will be exposed on, e.g.: |
| 48 | + |
| 49 | +- `https://localhost:8000/oauth/gitlab` for port-forwarding and testing |
| 50 | +- `https://git.example.com/oauth/gitlab` for production use |
| 51 | + |
| 52 | +Save your application, taking note of the **Client ID** and **Client Secret**. Save |
| 53 | +them into the `git-provider-credentials` secret, along with: |
| 54 | + |
| 55 | +- `GIT_HOST_TYPES` to tell WGE that the host is gitlab |
| 56 | +- `GITLAB_HOSTNAME` where the OAuth app is hosted |
| 57 | + |
| 58 | +**Replace values** in this snippet and run: |
| 59 | + |
| 60 | +```bash |
| 61 | +kubectl create secret generic git-provider-credentials --namespace=flux-system \ |
| 62 | + --from-literal="GITLAB_CLIENT_ID=13457" \ |
| 63 | + --from-literal="GITLAB_CLIENT_SECRET=24680" \ |
| 64 | + --from-literal="GITLAB_HOSTNAME=git.example.com" \ |
| 65 | + --from-literal="GIT_HOST_TYPES=git.example.com=gitlab" |
| 66 | +``` |
| 67 | + |
| 68 | +</TabItem> |
| 69 | +<TabItem value="bitbucket-server" label="BitBucket Server"> |
| 70 | + |
| 71 | +Create a new [incoming application link](https://confluence.atlassian.com/bitbucketserver/configure-an-incoming-link-1108483657.html) from |
| 72 | +the BitBucket administration dashboard. You will be asked to enter a unique name and the redirect URL for the external application. The redirect URL |
| 73 | +should be set to `$WGE_DASHBOARD_URL/oauth/bitbucketserver`. You will also need to select permissions for the application. The minimum set of |
| 74 | +permissions needed for WGE to create pull requests on behalf of users is `Repositories - Write`. An example of configuring these settings is shown below. |
| 75 | + |
| 76 | +<figure> |
| 77 | + |
| 78 | +<img src={oauthBitbucket} width="500"/> |
| 79 | + |
| 80 | +<figcaption>Configuring a new incoming application link</figcaption> |
| 81 | +</figure> |
| 82 | + |
| 83 | + |
| 84 | +Save your application and take note of the **Client ID** and **Client Secret**. Save |
| 85 | +them into the `git-provider-credentials` secret, along with: |
| 86 | + |
| 87 | +- `GIT_HOST_TYPES` to tell WGE that the host is bitbucket-server |
| 88 | +- `BITBUCKET_SERVER_HOSTNAME` where the OAuth app is hosted |
| 89 | + |
| 90 | +**Replace values** in this snippet and run: |
| 91 | + |
| 92 | +```bash |
| 93 | +kubectl create secret generic git-provider-credentials --namespace=flux-system \ |
| 94 | + --from-literal="BITBUCKET_SERVER_CLIENT_ID=13457" \ |
| 95 | + --from-literal="BITBUCKET_SERVER_CLIENT_SECRET=24680" \ |
| 96 | + --from-literal="BITBUCKET_SERVER_HOSTNAME=git.example.com" \ |
| 97 | + --from-literal="GIT_HOST_TYPES=git.example.com=bitbucket-server" |
| 98 | +``` |
| 99 | + |
| 100 | +If the secret is already present, use the following command to update it using your default editor: |
| 101 | + |
| 102 | +```bash |
| 103 | +kubectl edit secret generic git-provider-credentials --namespace=flux-system |
| 104 | +``` |
| 105 | + |
| 106 | +:::info |
| 107 | + |
| 108 | +If BitBucket Server is running on the default port (7990), make sure you include the port number in the values of the secret. For example: `GIT_HOST_TYPES=git.example.com:7990=bitbucket-server` |
| 109 | + |
| 110 | +::: |
| 111 | + |
| 112 | +</TabItem> |
| 113 | + |
| 114 | +<TabItem value="azure-devops" label="Azure DevOps"> |
| 115 | + |
| 116 | +Navigate to [VisualStudio](https://app.vsaex.visualstudio.com/app/register) and register a new application, as explained in the [docs](https://learn.microsoft.com/en-us/azure/devops/integrate/get-started/authentication/oauth?view=azure-devops#1-register-your-app). Set the authorization callback URL and select which scopes to grant. Set the callback URL to `$WGE_DASHBOARD_URL/oauth/azuredevops`. |
| 117 | + |
| 118 | +Select the `Code (read and write)` scope from the list. This is necessary so that WGE can create pull requests on behalf of users. An example of configuring these settings is shown below. |
| 119 | + |
| 120 | +<figure> |
| 121 | +<img src={oauthAzureDevOps}/> |
| 122 | +<figcaption>Creating a new application</figcaption> |
| 123 | +</figure> |
| 124 | + |
| 125 | +After creating your application, you will be presented with the application settings. Take note of the `App ID` and `Client Secret` values—you will use them to configure WGE. |
| 126 | + |
| 127 | +<figure> |
| 128 | +<img src={oauthAzureDevOpsSuccess}/> |
| 129 | +<figcaption>Application settings</figcaption> |
| 130 | +</figure> |
| 131 | + |
| 132 | +In your cluster, create a secret named `git-provider-credentials` that contains the `App ID` and `Client Secret` values from the newly created application. |
| 133 | + |
| 134 | +**Replace values** in this snippet and run: |
| 135 | + |
| 136 | +```bash |
| 137 | +kubectl create secret generic git-provider-credentials --namespace=flux-system \ |
| 138 | + --from-literal="AZURE_DEVOPS_CLIENT_ID='App ID value'" \ |
| 139 | + --from-literal="AZURE_DEVOPS_CLIENT_SECRET='Client Secret value'" |
| 140 | +``` |
| 141 | + |
| 142 | +WGE is now configured to ask users for authorization the next time a pull request must be created as part of using a template. |
| 143 | +Note that each user can view and manage which applications they have authorized by navigating to https://app.vsaex.visualstudio.com/me. |
| 144 | + |
| 145 | +</TabItem> |
| 146 | +</Tabs> |
| 147 | + |
| 148 | +## Enable Cluster Management via Cluster API |
| 149 | + |
| 150 | +// TODO should be at the getting started level and link to the other guides in depth. |
| 151 | + |
| 152 | +## Enable Policy via Weave Policy |
| 153 | + |
| 154 | +To install [Policy Agent](../../policy/intro.mdx) follow any of the following approaches: |
| 155 | + |
| 156 | +<Tabs groupId="policy agent" default> |
| 157 | +<TabItem value="cli" label="cli"> |
| 158 | + |
| 159 | +You could configure this stage by using the following flags and examples: |
| 160 | + |
| 161 | +```bash |
| 162 | + # install Policy Agent alongside Weave GitOps Enterprise |
| 163 | + gitops bootstrap --components-extra="policy-agent" |
| 164 | +``` |
| 165 | + |
| 166 | +For more information about the CLI configurations, check the below sections [here](#cli-configurations) |
| 167 | +</TabItem> |
| 168 | +<TabItem value="manual" label="manual"> |
| 169 | + |
| 170 | +[Policy agent](../../policy/intro.mdx) comes packaged with the WGE chart. To install it, set the following values: |
| 171 | + |
| 172 | +- `values.policy-agent.enabled`: set to true to install the agent with WGE |
| 173 | +- `values.policy-agent.config.accountId`: organization name, used as identifier |
| 174 | +- `values.policy-agent.config.clusterId`: unique identifier for the cluster |
| 175 | + |
| 176 | +Commit and push all the files |
| 177 | + |
| 178 | +```bash |
| 179 | +git add clusters/management/weave-gitops-enterprise.yaml |
| 180 | +git commit -m "Deploy Weave GitOps Enterprise" |
| 181 | +git push |
| 182 | +``` |
| 183 | + |
| 184 | +Flux will reconcile the helm-release and WGE will be deployed into the cluster. You can check the `flux-system` namespace to verify all pods are running. |
| 185 | + |
| 186 | +</TabItem> |
| 187 | +</Tabs> |
| 188 | + |
| 189 | +## Enable Infrastructure Management via Tf-Controller |
| 190 | + |
| 191 | + |
| 192 | +## Advanced Topics |
| 193 | + |
| 194 | +### OIDC |
| 195 | + |
| 196 | +#### Customization |
| 197 | + |
| 198 | +For some OIDC configurations, you may need to customise the requested [scopes](https://openid.net/specs/openid-connect-core-1_0.html#ScopeClaims) or [claims](https://openid.net/specs/openid-connect-core-1_0.html#Claims). |
| 199 | + |
| 200 | +The `oidcUsernamePrefix` and `oidcGroupsPrefix` work in the same way as the Kubernetes [kube-apiserver](https://kubernetes.io/docs/reference/command-line-tools-reference/kube-apiserver/) command-line options, if you need them for Kubernetes, you will likely need them here. |
| 201 | + |
| 202 | +#### Scopes |
| 203 | + |
| 204 | +By default, the following scopes are requested: "openid","offline_access","email","groups". |
| 205 | + |
| 206 | +The "openid" scope is **mandatory** for OpenID auth and will be added if not provided. The "email" and "groups" scopes are commonly used as unique identifiers in organisations. |
| 207 | + |
| 208 | +"offline_access" allows us to refresh OIDC tokens to keep login sessions alive for as long as a refresh token is valid. You can, however, change the defaults. |
| 209 | +```sh |
| 210 | +kubectl create secret generic oidc-auth \ |
| 211 | + --namespace flux-system \ |
| 212 | + --from-literal=issuerURL=$oidc-issuer-url \ |
| 213 | + --from-literal=clientID=$client-id \ |
| 214 | + --from-literal=clientSecret=$client-secret \ |
| 215 | + --from-literal=redirectURL=redirect-url \ |
| 216 | + --from-literal=tokenDuration=token-duration \ |
| 217 | + --from-literal=customScopes=custom,scopes |
| 218 | +``` |
| 219 | +The format for the `customScopes` key is a comma-separated list of scopes to request. In this case, "custom", "scopes", and "openid" would be requested. |
| 220 | + |
| 221 | +#### Claims |
| 222 | + |
| 223 | +By default, the following claims are parsed from the OpenID [ID Token](https://openid.net/specs/openid-connect-core-1_0.html#CodeIDToken) "email" and "groups". These are presented as the `user` and `groups` when WGE communicates with your Kubernetes API server. |
| 224 | + |
| 225 | +This is equivalent to [configuring](https://kubernetes.io/docs/reference/access-authn-authz/authentication/#configuring-the-api-server) your `kube-apiserver` with `--oidc-username-claim=email --oidc-groups-claim=groups`. |
| 226 | + |
| 227 | +Again, you can configure these from the `oidc-auth` `Secret`. |
| 228 | + |
| 229 | +```sh |
| 230 | +kubectl create secret generic oidc-auth \ |
| 231 | + --namespace flux-system \ |
| 232 | + --from-literal=issuerURL=oidc-issuer-url \ |
| 233 | + --from-literal=clientID=client-id \ |
| 234 | + --from-literal=clientSecret=client-secret \ |
| 235 | + --from-literal=redirectURL=redirect-url \ |
| 236 | + --from-literal=tokenDuration=token-duration \ |
| 237 | + --from-literal=claimUsername=sub \ |
| 238 | + --from-literal=claimGroups=groups |
| 239 | +``` |
| 240 | +There are two separate configuration keys. You can override them separately. They should match your `kube-apiserver` configuration. |
| 241 | + |
| 242 | +### Cluster User |
| 243 | + |
| 244 | +#### Update Username or Password |
| 245 | + |
| 246 | +To change either the username or the password, recreate the `cluster-user-auth` |
| 247 | +with the new details. |
| 248 | + |
| 249 | +Only one Cluster User can be created this way. To add more users, enable an OIDC provider. |
| 250 | + |
| 251 | +#### Update Permissions |
| 252 | + |
| 253 | +If required, the permissions can be expanded with the `rbac.additionalRules` field in the |
| 254 | +[Helm Chart](../../references/helm-reference.md). |
| 255 | + |
| 256 | +Follow the instructions in the next section in order to configure RBAC correctly. |
| 257 | + |
| 258 | +#### Remove It |
| 259 | + |
| 260 | +To remove the Cluster User as a login method, set the following values in the |
| 261 | +[Helm Chart](../../references/helm-reference.md): |
| 262 | + |
| 263 | +```yaml |
| 264 | +# |
| 265 | +adminUser: |
| 266 | + create: false |
| 267 | +# |
| 268 | +additionalArgs: |
| 269 | +- --auth-methods=oidc |
| 270 | +# |
| 271 | +``` |
| 272 | +:::caution If you are disabling an already existing Cluster User |
| 273 | + |
| 274 | +If you are disabling an already existing Cluster User, you will need to |
| 275 | +manually delete the Kubernetes Secret and any User Roles that were created on |
| 276 | +the cluster. |
| 277 | + |
| 278 | +::: |
| 279 | + |
| 280 | +### User Permissions |
| 281 | + |
| 282 | +This section discusses the [Kubernetes permissions](https://kubernetes.io/docs/reference/access-authn-authz/rbac/) |
| 283 | +needed by Weave GitOps application users and groups. At a minimum, a User should be bound to a Role in the `flux-system` namespace—which is where |
| 284 | +Flux stores its resources by default—with the following permissions: |
| 285 | + |
| 286 | +```yaml |
| 287 | +rules: |
| 288 | + # Flux Resources |
| 289 | + - apiGroups: ["source.toolkit.fluxcd.io"] |
| 290 | + resources: [ "buckets", "helmcharts", "gitrepositories", "helmrepositories", "ocirepositories" ] |
| 291 | + verbs: [ "get", "list", "watch", "patch" ] |
| 292 | + |
| 293 | + - apiGroups: ["kustomize.toolkit.fluxcd.io"] |
| 294 | + resources: [ "kustomizations" ] |
| 295 | + verbs: [ "get", "list", "watch", "patch" ] |
| 296 | + |
| 297 | + - apiGroups: ["helm.toolkit.fluxcd.io"] |
| 298 | + resources: [ "helmreleases" ] |
| 299 | + verbs: [ "get", "list", "watch", "patch" ] |
| 300 | + |
| 301 | + - apiGroups: [ "notification.toolkit.fluxcd.io" ] |
| 302 | + resources: [ "providers", "alerts" ] |
| 303 | + verbs: [ "get", "list", "watch", "patch" ] |
| 304 | + |
| 305 | + - apiGroups: ["infra.contrib.fluxcd.io"] |
| 306 | + resources: ["terraforms"] |
| 307 | + verbs: [ "get", "list", "watch", "patch" ] |
| 308 | + |
| 309 | + # Read access for all other Kubernetes objects |
| 310 | + - apiGroups: ["*"] |
| 311 | + resources: ["*"] |
| 312 | + verbs: [ "get", "list", "watch" ] |
| 313 | +``` |
| 314 | +
|
| 315 | +For a wider scope, the User can be bound to a ClusterRole with the same set. |
| 316 | +
|
| 317 | +On top of this you can add other permissions to view WGE resources like `GitOpsSets` and `Templates`. |
| 318 | + |
| 319 | +#### Flux Resources |
| 320 | + |
| 321 | +The following table lists resources that Flux works with directly. |
| 322 | + |
| 323 | +| API Group | Resources | Permissions | |
| 324 | +| ------------------------------ | ----------------------------------------------------------------------- | ---------------- | |
| 325 | +| kustomize.toolkit.fluxcd.io | kustomizations | get, list, patch | |
| 326 | +| helm.toolkit.fluxcd.io | Helm Releases | get, list, patch | |
| 327 | +| source.toolkit.fluxcd.io | buckets, Helm charts, Git repositories, Helm repositories, OCI repositories | get, list, patch | |
| 328 | +| notification.toolkit.fluxcd.io | providers, alerts | get, list | |
| 329 | +| infra.contrib.fluxcd.io | [Terraform](https://github.com/weaveworks/tf-controller) | get, list, patch | |
| 330 | + |
| 331 | +Weave GitOps needs to be able to query the [CRDs](https://fluxcd.io/docs/components/) that Flux uses before it can accurately display Flux state. The |
| 332 | +`get` and `list` permissions facilitate this. |
| 333 | + |
| 334 | +The `patch` permissions are used for two features: to suspend and resume |
| 335 | +reconciliation of a resource by modifying the 'spec' of a resource, |
| 336 | +and to force reconciliation of a resource by modifying resource annotations. These features work in the same way that `flux suspend`, |
| 337 | +`flux resume`, and `flux reconcile` does on the CLI. |
| 338 | + |
| 339 | +#### Resources Managed via Flux |
| 340 | + |
| 341 | +| API Group | Resources | Permissions | |
| 342 | +|---------------------------|--------------------------------------------------------------------------------|------------------| |
| 343 | +| "" | configmaps, secrets, pods, services, persistent volumes, persistent volume claims | get, list, watch | |
| 344 | +| apps | deployments, replica sets, stateful sets | get, list, watch | |
| 345 | +| batch | jobs, cron jobs | get, list, watch | |
| 346 | +| autoscaling | horizontal pod autoscalers | get, list, watch | |
| 347 | +| rbac.authorization.k8s.io | roles, cluster roles, rolebindings, cluster role bindings | get, list, watch | |
| 348 | +| networking.k8s.io | ingresses | get, list, watch | |
| 349 | + |
| 350 | +Weave GitOps reads basic resources so that it can monitor the effect that Flux has |
| 351 | +on what's running. |
| 352 | + |
| 353 | +Reading `secrets` enables Weave GitOps to monitor the state of Helm releases |
| 354 | +as that's where it stores the [state by default](https://helm.sh/docs/faq/changes_since_helm2/#secrets-as-the-default-storage-driver). |
| 355 | +For clarity this these are the Helm release objects _not_ the Flux HelmRelease |
| 356 | +resource (which are dealt with by the earlier section). |
| 357 | + |
| 358 | +#### Feedback from Flux |
| 359 | + |
| 360 | +Flux communicates the status of itself primarily via events. |
| 361 | +These events will show when reconciliations start and stop, whether they're successful, |
| 362 | +and information as to why they're not. |
| 363 | + |
| 364 | +### Customise the UI |
| 365 | + |
| 366 | +#### Login |
| 367 | + |
| 368 | +The label of the OIDC button on the login screen is configurable via a feature flag environment variable. |
| 369 | +This can give your users a more familiar experience when logging in. |
| 370 | + |
| 371 | +Adjust the configuration in the Helm `values.yaml` file or the `spec.values` section of the Weave GitOps `HelmRelease` resource: |
| 372 | + |
| 373 | +```yaml |
| 374 | +extraEnvVars: |
| 375 | + - name: WEAVE_GITOPS_FEATURE_OIDC_BUTTON_LABEL |
| 376 | + value: "Login with ACME" |
| 377 | +``` |
| 378 | + |
| 379 | + |
| 380 | + |
0 commit comments