Skip to content

Commit

Permalink
feat(Tekton): use Kubernetes plugin permissions (#2942)
Browse files Browse the repository at this point in the history
* feat(Tekton): use Kubernetes plugin permissions

Signed-off-by: Bryan Ramos <bramos@redhat.com>

* Add a changeset

Signed-off-by: Bryan Ramos <bramos@redhat.com>

* Update permission alert message

Signed-off-by: Bryan Ramos <bramos@redhat.com>

* Update docs

Signed-off-by: Bryan Ramos <bramos@redhat.com>

* Remove permissions from tekton-common plugin

Signed-off-by: Bryan Ramos <bramos@redhat.com>

* Remove old changeset

Signed-off-by: Bryan Ramos <bramos@redhat.com>

* Fix mispelling

Signed-off-by: Bryan Ramos <bramos@redhat.com>

---------

Signed-off-by: Bryan Ramos <bramos@redhat.com>
  • Loading branch information
CryptoRodeo authored Feb 24, 2025
1 parent 5770418 commit 48e0647
Show file tree
Hide file tree
Showing 8 changed files with 1,518 additions and 1,396 deletions.
6 changes: 6 additions & 0 deletions workspaces/tekton/.changeset/major-camels-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@backstage-community/plugin-tekton-common': minor
'@backstage-community/plugin-tekton': minor
---

Use Kubernetes plugin permissions for Tekton plugin, remove tekton-specific permissions from tekton-common plugin
8 changes: 0 additions & 8 deletions workspaces/tekton/plugins/tekton-common/report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,8 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { BasicPermission } from '@backstage/plugin-permission-common';

// @public
export enum TektonAnnotations {
CICD = 'tekton.dev/cicd',
}

// @public
export const tektonPermissions: BasicPermission[];

// @public
export const tektonViewPermission: BasicPermission;
```
1 change: 0 additions & 1 deletion workspaces/tekton/plugins/tekton-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@
*/

export * from './annotations';
export * from './permissions';
35 changes: 0 additions & 35 deletions workspaces/tekton/plugins/tekton-common/src/permissions.ts

This file was deleted.

9 changes: 9 additions & 0 deletions workspaces/tekton/plugins/tekton/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ The Tekton plugin enables you to visualize the `PipelineRun` resources available
);
```

#### Permissions

If you are using permissions, please ensure that the following Kubernetes permissions are enabled:

- `kubernetes.clusters.read `
- `kubernetes.resources.read`

Read [the documentation](https://github.com/backstage/backstage/blob/master/docs/features/kubernetes/permissions.md) for more info on these permissions.

## For users

### Using the Tekton plugin in Backstage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,24 @@
import React from 'react';

import { Alert, AlertTitle } from '@material-ui/lab';
import {
kubernetesClustersReadPermission,
kubernetesResourcesReadPermission,
} from '@backstage/plugin-kubernetes-common';

const permissions = [
kubernetesClustersReadPermission,
kubernetesResourcesReadPermission,
]
.map(p => p.name)
.join(', ');

const PermissionAlert = () => {
return (
<Alert severity="warning" data-testid="no-permission-alert">
<AlertTitle>Permission required</AlertTitle>
To view Tekton Pipeline Runs, contact your administrator to give you the
tekton.view.read permission.
following permission(s): {permissions}.
</Alert>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@
*/
import { usePermission } from '@backstage/plugin-permission-react';

import { tektonViewPermission } from '@backstage-community/plugin-tekton-common';
import {
kubernetesClustersReadPermission,
kubernetesResourcesReadPermission,
} from '@backstage/plugin-kubernetes-common';

export const useTektonViewPermission = () => {
const tektonViewPermissionResult = usePermission({
permission: tektonViewPermission,
const clusterReadPermission = usePermission({
permission: kubernetesClustersReadPermission,
});

return tektonViewPermissionResult.allowed;
const clusterResourcesReadPermission = usePermission({
permission: kubernetesResourcesReadPermission,
});

return (
clusterReadPermission.allowed && clusterResourcesReadPermission.allowed
);
};
Loading

0 comments on commit 48e0647

Please sign in to comment.