Skip to content

Commit 11aa71b

Browse files
authored
fix(edge functions secrets): allow read-only role to read secrets metadata (supabase#40667)
According to our API permissions model, the read-only role can also read secrets metadata (the actual secret itself is not viewable by anybdoy). Updating the frontend UI to match.
1 parent 25dc1ef commit 11aa71b

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

apps/studio/components/interfaces/Functions/EdgeFunctionSecrets/EdgeFunctionSecrets.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,25 @@ import AddNewSecretForm from './AddNewSecretForm'
1818
import EdgeFunctionSecret from './EdgeFunctionSecret'
1919
import { EditSecretSheet } from './EditSecretSheet'
2020

21-
const EdgeFunctionSecrets = () => {
21+
export const EdgeFunctionSecrets = () => {
2222
const { ref: projectRef } = useParams()
2323
const [searchString, setSearchString] = useState('')
2424

2525
// Track the ID being deleted to exclude it from error checking
2626
const deletingSecretNameRef = useRef<string | null>(null)
2727

28-
const { can: canReadSecrets, isLoading: isLoadingPermissions } = useAsyncCheckPermissions(
29-
PermissionAction.SECRETS_READ,
28+
const { can: canReadSecrets, isLoading: isLoadingSecretsPermissions } = useAsyncCheckPermissions(
29+
PermissionAction.FUNCTIONS_SECRET_READ,
3030
'*'
3131
)
3232
const { can: canUpdateSecrets } = useAsyncCheckPermissions(PermissionAction.SECRETS_WRITE, '*')
3333

34-
const { data, error, isLoading, isSuccess, isError } = useSecretsQuery({
35-
projectRef: projectRef,
36-
})
34+
const { data, error, isLoading, isSuccess, isError } = useSecretsQuery(
35+
{
36+
projectRef: projectRef,
37+
},
38+
{ enabled: canReadSecrets }
39+
)
3740

3841
const { setValue: setSelectedSecretToEdit, value: selectedSecretToEdit } =
3942
useQueryStateWithSelect({
@@ -82,10 +85,14 @@ const EdgeFunctionSecrets = () => {
8285
<TableHead key="actions" />,
8386
]
8487

88+
const showLoadingState = isLoadingSecretsPermissions || (canReadSecrets && isLoading)
89+
8590
return (
8691
<>
87-
{isLoading || isLoadingPermissions ? (
92+
{showLoadingState ? (
8893
<GenericSkeletonLoader />
94+
) : !canReadSecrets ? (
95+
<NoPermission resourceText="view this project's edge function secrets" />
8996
) : (
9097
<>
9198
{isError && <AlertError error={error} subject="Failed to retrieve project secrets" />}
@@ -187,5 +194,3 @@ const EdgeFunctionSecrets = () => {
187194
</>
188195
)
189196
}
190-
191-
export default EdgeFunctionSecrets

apps/studio/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"@supabase/mcp-utils": "^0.2.0",
6363
"@supabase/pg-meta": "workspace:*",
6464
"@supabase/realtime-js": "catalog:",
65-
"@supabase/shared-types": "0.1.80",
65+
"@supabase/shared-types": "0.1.83",
6666
"@supabase/sql-to-rest": "^0.1.6",
6767
"@supabase/supabase-js": "catalog:",
6868
"@tanstack/react-query": "^4.42.0",

apps/studio/pages/project/[ref]/functions/secrets.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import EdgeFunctionSecrets from 'components/interfaces/Functions/EdgeFunctionSecrets/EdgeFunctionSecrets'
1+
import { EdgeFunctionSecrets } from 'components/interfaces/Functions/EdgeFunctionSecrets/EdgeFunctionSecrets'
22
import { FunctionsSecretsEmptyStateLocal } from 'components/interfaces/Functions/FunctionsEmptyState'
33
import DefaultLayout from 'components/layouts/DefaultLayout'
44
import EdgeFunctionsLayout from 'components/layouts/EdgeFunctionsLayout/EdgeFunctionsLayout'

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)