Skip to content

Commit bb3f1ba

Browse files
committed
fix(auth): derive grok auth file owner
1 parent 0c29c14 commit bb3f1ba

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

packages/app/src/lib/usecases/auth-grok-oauth.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ const printOauthInstructions = (): Effect.Effect<void> =>
8888
})
8989

9090
const grokAuthPermissionScript = [
91-
"chown -R 1000:1000 \"$1\"",
91+
"target_uid=\"${CHOWN_UID:-$(stat -c %u \"$1\" 2>/dev/null || id -u)}\"",
92+
"target_gid=\"${CHOWN_GID:-$(stat -c %g \"$1\" 2>/dev/null || id -g)}\"",
93+
"chown -R \"$target_uid:$target_gid\" \"$1\"",
9294
"find \"$1\" -type d -exec chmod 700 {} +",
9395
"find \"$1\" -type f -exec chmod 600 {} +"
9496
].join(" && ")
@@ -128,7 +130,7 @@ const fixGrokAuthPermissions = (cwd: string, hostPath: string, containerPath: st
128130
* @effect CommandExecutor; invokes Docker and writes credentials under the selected account path.
129131
* @invariant successful completion leaves credentials scoped to accountPath and not to project source files.
130132
* @precondition Docker is available and options.image contains the official Grok CLI binary.
131-
* @postcondition accountPath permissions are normalized for the project SSH user or a typed error is returned.
133+
* @postcondition accountPath ownership follows the mounted account root or a typed error is returned.
132134
* @complexity O(n) local argument construction plus unbounded external OAuth interaction time.
133135
* @throws Never - failures are modeled as AuthError, CommandFailedError, or PlatformError in the Effect type.
134136
*/

packages/lib/src/usecases/auth-grok-oauth.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ const printOauthInstructions = (): Effect.Effect<void> =>
8888
})
8989

9090
const grokAuthPermissionScript = [
91-
"chown -R 1000:1000 \"$1\"",
91+
"target_uid=\"${CHOWN_UID:-$(stat -c %u \"$1\" 2>/dev/null || id -u)}\"",
92+
"target_gid=\"${CHOWN_GID:-$(stat -c %g \"$1\" 2>/dev/null || id -g)}\"",
93+
"chown -R \"$target_uid:$target_gid\" \"$1\"",
9294
"find \"$1\" -type d -exec chmod 700 {} +",
9395
"find \"$1\" -type f -exec chmod 600 {} +"
9496
].join(" && ")
@@ -128,7 +130,7 @@ const fixGrokAuthPermissions = (cwd: string, hostPath: string, containerPath: st
128130
* @effect CommandExecutor; invokes Docker and writes credentials under the selected account path.
129131
* @invariant successful completion leaves credentials scoped to accountPath and not to project source files.
130132
* @precondition Docker is available and options.image contains the official Grok CLI binary.
131-
* @postcondition accountPath permissions are normalized for the project SSH user or a typed error is returned.
133+
* @postcondition accountPath ownership follows the mounted account root or a typed error is returned.
132134
* @complexity O(n) local argument construction plus unbounded external OAuth interaction time.
133135
* @throws Never - failures are modeled as AuthError, CommandFailedError, or PlatformError in the Effect type.
134136
*/

0 commit comments

Comments
 (0)