Skip to content

chore(openfga): replace member-type bootstrap script with cleanup#24

Merged
emsearcy merged 1 commit into
mainfrom
feat/LFXV2-1356-cleanup-member-type
Apr 1, 2026
Merged

chore(openfga): replace member-type bootstrap script with cleanup#24
emsearcy merged 1 commit into
mainfrom
feat/LFXV2-1356-cleanup-member-type

Conversation

@emsearcy
Copy link
Copy Markdown
Contributor

@emsearcy emsearcy commented Mar 31, 2026

Summary

Removes scripts/create-membership-auditors-team.sh and replaces it with scripts/cleanup-openfga-member-type.sh, a one-time data migration script to accompany the removal of the stub member OpenFGA type in lfx-v2-helm#120.

Jira

LFXV2-1356

What the cleanup script does

  1. Deletes all member:* object tuplesteam:membership-auditors#member -> auditor -> member:<uuid> (7,451 tuples in prod, 0 in dev)
  2. Deletes all team:membership-auditors user membership tuplesuser:* -> member -> team:membership-auditors (5 users in prod)

The member type is being replaced by the new b2b_org, project_membership, and key_contact types.

Usage

# Dry run first (recommended)
./scripts/cleanup-openfga-member-type.sh --dry-run

# Then for real (requires port-forward to target OpenFGA on localhost:8080)
./scripts/cleanup-openfga-member-type.sh

Environment variables OPENFGA_URL and OPENFGA_STORE_ID can be overridden if needed.

@emsearcy emsearcy requested a review from a team as a code owner March 31, 2026 22:44
Copilot AI review requested due to automatic review settings March 31, 2026 22:44
Remove scripts/create-membership-auditors-team.sh and replace with
scripts/cleanup-openfga-member-type.sh, which deletes:
  - All team:membership-auditors#member -> auditor -> member:<uuid> tuples
    (7,451 in prod)
  - All user -> member -> team:membership-auditors tuples (5 in prod)

This is a one-time data migration to accompany the removal of the stub
`member` OpenFGA type in lfx-v2-helm (LFXV2-1356), which is replaced
by the new b2b_org, project_membership, and key_contact types.

The script supports --dry-run for safe pre-flight verification.

🤖 Generated with [GitHub Copilot](https://github.com/features/copilot) (via Zed)

Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
@emsearcy emsearcy force-pushed the feat/LFXV2-1356-cleanup-member-type branch from 11fab8c to 568f911 Compare March 31, 2026 22:46
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Replaces the prior OpenFGA bootstrap script for the membership-auditors team with a one-time cleanup/migration script intended to remove tuples associated with the deprecated member OpenFGA type.

Changes:

  • Remove scripts/create-membership-auditors-team.sh (NATS/fga-sync bootstrap helper).
  • Add scripts/cleanup-openfga-member-type.sh to enumerate and delete member-type tuples (with optional --dry-run) via the OpenFGA HTTP API.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
scripts/create-membership-auditors-team.sh Deleted legacy bootstrap script that published membership updates via NATS/fga-sync.
scripts/cleanup-openfga-member-type.sh Added one-time cleanup script to collect and delete tuples tied to the removed member type.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/cleanup-openfga-member-type.sh
Comment thread scripts/cleanup-openfga-member-type.sh
Comment on lines +56 to +63
local resp
resp=$(curl -s -X POST "${BASE_URL}/stores/${STORE_ID}/write" \
-H 'Content-Type: application/json' \
-d "$payload")

# OpenFGA returns an empty body on success, or a JSON error object on failure
if echo "$resp" | jq -e '.code' >/dev/null 2>&1; then
echo "ERROR deleting batch: $(echo "$resp" | jq -r '.message')"
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both /write and /read calls use curl -s without failing on non-2xx HTTP responses. If OpenFGA returns an HTTP error with an empty/non-JSON body (or a proxy returns HTML), the .code check can be bypassed and the script may incorrectly treat the operation as successful. Use curl --fail-with-body (or -f plus capturing the status code) and validate that the response is valid JSON before parsing error fields.

Suggested change
local resp
resp=$(curl -s -X POST "${BASE_URL}/stores/${STORE_ID}/write" \
-H 'Content-Type: application/json' \
-d "$payload")
# OpenFGA returns an empty body on success, or a JSON error object on failure
if echo "$resp" | jq -e '.code' >/dev/null 2>&1; then
echo "ERROR deleting batch: $(echo "$resp" | jq -r '.message')"
local http_status
local resp
local http_output
http_output=$(curl -sS -w '%{http_code}' -X POST "${BASE_URL}/stores/${STORE_ID}/write" \
-H 'Content-Type: application/json' \
-d "$payload") || {
echo "ERROR deleting batch: HTTP request to OpenFGA failed"
echo "Raw response:"
echo "$http_output"
exit 1
}
http_status=${http_output: -3}
resp=${http_output::-3}
# Treat any non-2xx HTTP status as an error
if [[ "$http_status" != 2?? ]]; then
echo "ERROR deleting batch: OpenFGA returned HTTP status $http_status"
if [[ -n "$resp" ]] && echo "$resp" | jq -e . >/dev/null 2>&1; then
# Try to surface a JSON error message if present
if echo "$resp" | jq -e '.message' >/dev/null 2>&1; then
echo "Message: $(echo "$resp" | jq -r '.message')"
else
echo "Response body (JSON):"
echo "$resp" | jq .
fi
elif [[ -n "$resp" ]]; then
echo "Response body (non-JSON):"
echo "$resp"
fi
exit 1
fi
# OpenFGA returns an empty body on success, or a JSON error object on failure.
# If a JSON body with a .code field is present, treat it as an error.
if [[ -n "$resp" ]] && echo "$resp" | jq -e . >/dev/null 2>&1 && \
echo "$resp" | jq -e '.code' >/dev/null 2>&1; then
echo "ERROR deleting batch: $(echo "$resp" | jq -r '.message // "Unknown error"')"

Copilot uses AI. Check for mistakes.
Comment thread scripts/cleanup-openfga-member-type.sh
Comment thread scripts/cleanup-openfga-member-type.sh
@emsearcy emsearcy requested a review from jordane March 31, 2026 22:47
@emsearcy
Copy link
Copy Markdown
Contributor Author

This has now been run successfully against production. PR just for reference.

@emsearcy emsearcy merged commit 36b131a into main Apr 1, 2026
9 checks passed
@emsearcy emsearcy deleted the feat/LFXV2-1356-cleanup-member-type branch April 1, 2026 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants