Enforce customer boundaries on token administration and finalize fleet navigation
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
-- Token administrators may see and revoke a credential only when its full
|
||||
-- audience is within their current customer-management rights.
|
||||
CREATE FUNCTION can_manage_mcp_token(actor text,id uuid,visible uuid[]) RETURNS boolean
|
||||
LANGUAGE sql STABLE SECURITY DEFINER SET search_path=pg_catalog,public AS $$
|
||||
SELECT EXISTS (
|
||||
SELECT FROM mcp_tokens t
|
||||
JOIN customer_member_index issuer ON issuer.principal=actor AND issuer.customer=t.tenant_id
|
||||
WHERE t.token_id=id AND t.tenant_id=nullif(current_setting('app.tenant_id',true),'')::uuid
|
||||
AND issuer.kind='human' AND 'tokens:manage'=ANY(issuer.permissions) AND t.tenant_id=ANY(visible)
|
||||
AND CASE WHEN t.all_customers THEN is_customer_admin(actor)
|
||||
ELSE NOT EXISTS (
|
||||
SELECT FROM unnest(coalesce(t.customer_ids,ARRAY[t.tenant_id])) AS target(customer_id)
|
||||
WHERE NOT target.customer_id=ANY(visible) OR NOT EXISTS (
|
||||
SELECT FROM customer_member_index m WHERE m.principal=actor AND m.customer=target.customer_id
|
||||
AND m.kind='human' AND 'tokens:manage'=ANY(m.permissions)
|
||||
)
|
||||
) END
|
||||
);
|
||||
$$;
|
||||
REVOKE ALL ON FUNCTION can_manage_mcp_token(text,uuid,uuid[]) FROM PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION can_manage_mcp_token(text,uuid,uuid[]) TO rmm_app;
|
||||
|
||||
ALTER FUNCTION revoke_mcp_token(text,uuid,uuid) RENAME TO revoke_mcp_token_data;
|
||||
REVOKE ALL ON FUNCTION revoke_mcp_token_data(text,uuid,uuid) FROM rmm_app;
|
||||
CREATE FUNCTION revoke_mcp_token(actor text,id uuid,event uuid,visible uuid[]) RETURNS boolean
|
||||
LANGUAGE plpgsql SECURITY DEFINER SET search_path=pg_catalog,public AS $$
|
||||
BEGIN
|
||||
IF NOT can_manage_mcp_token(actor,id,visible) THEN RETURN false; END IF;
|
||||
RETURN revoke_mcp_token_data(actor,id,event);
|
||||
END $$;
|
||||
REVOKE ALL ON FUNCTION revoke_mcp_token(text,uuid,uuid,uuid[]) FROM PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION revoke_mcp_token(text,uuid,uuid,uuid[]) TO rmm_app;
|
||||
Reference in New Issue
Block a user