-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor auth models to use concrete auth.Actor #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7ad058d
be6acfa
5866cfc
138068e
ad270f5
fac5998
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,16 @@ | ||
| # CodeRabbit Configuration File | ||
| # Reference: https://docs.coderabbit.ai/spec/configuration | ||
| # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json | ||
|
|
||
| language: "en-US" | ||
| tone_instruction: "Review code as a senior Go software engineer focusing on security practices, cryptographic hashing correctness, token lifecycles, and RBAC authorization." | ||
|
|
||
| reviews: | ||
| profile: "assertive" | ||
| tone_instructions: "Review code as a senior Go software engineer focusing on security practices, cryptographic hashing correctness, token lifecycles, and RBAC authorization." | ||
| auto_review: | ||
| enabled: true | ||
| drafts: false | ||
| high_level_summary: true | ||
| reviews_per_file: true | ||
| collapse_dependency_reviews: true | ||
|
|
||
| chat: | ||
| auto_reply: true |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -12,7 +12,16 @@ jobs: | |||||
| permissions: | ||||||
| contents: write | ||||||
| steps: | ||||||
| - uses: actions/checkout@v4 | ||||||
| - name: Checkout auth | ||||||
| uses: actions/checkout@v4 | ||||||
| - name: Checkout mdk | ||||||
| uses: actions/checkout@v4 | ||||||
| with: | ||||||
| repository: GoHyperrr/mdk | ||||||
| ref: ${{ github.head_ref || github.ref_name }} | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
ls -la .github/workflows || true
sed -n '1,120p' .github/workflows/ci.yml | nl -ba | sed -n '1,120p'
echo "----"
# show around line 21 specifically
nl -ba .github/workflows/ci.yml | sed -n '10,40p'
echo "----"
# find all occurrences of github.head_ref / ref_name / checkout repo usage
rg -n "github\.head_ref|\bref_name\b|checkout:" .github/workflows/ci.yml
echo "----"
# print checkout block(s) for context
rg -n "uses:\s*actions/checkout|GoHyperrr/mdk|repository:" .github/workflows/ci.yml -nRepository: GoHyperrr/auth Length of output: 283 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "---- workflows ----"
ls -la .github/workflows || true
echo "---- ci.yml (numbered via cat -n) ----"
cat -n .github/workflows/ci.yml | sed -n '1,120p'
echo "---- lines 15-35 ----"
sed -n '15,35p' .github/workflows/ci.yml
echo "---- checkout-related lines ----"
rg -n "actions/checkout|GoHyperrr/mdk|repository:|ref:\s*\$\{\{\s*github\.(head_ref|ref_name)\s*\|\|\s*github\.ref_name\s*\}\}" .github/workflows/ci.yml || true
echo "---- exact line containing github.head_ref/ref_name ----"
rg -n "github\.head_ref|\bgithub\.ref_name\b" .github/workflows/ci.yml || trueRepository: GoHyperrr/auth Length of output: 2258 Make GoHyperrr/mdk checkout use a stable ref (PRs won’t have matching branch names) In Proposed fix- ref: ${{ github.head_ref || github.ref_name }}
+ ref: main📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| path: mdk | ||||||
| - name: Move mdk to parent directory | ||||||
| run: mv mdk ../mdk | ||||||
| - uses: actions/setup-go@v5 | ||||||
| with: | ||||||
| go-version: '1.25' | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,10 @@ | ||||||||||||
| # Changelog | ||||||||||||
|
|
||||||||||||
| All notable changes to this project will be documented in this file. | ||||||||||||
|
|
||||||||||||
| ## [0.1.0] - 2026-06-05 | ||||||||||||
|
|
||||||||||||
| ### Added | ||||||||||||
| - Concrete auth.Actor persistence model implementing mdk.Actor interface. | ||||||||||||
|
Comment on lines
+7
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a blank line after the “Added” heading to satisfy markdownlint MD022. Insert one empty line between Line 7 and Line 8 to resolve the documented lint warning. Suggested patch ### Added
+
- Concrete auth.Actor persistence model implementing mdk.Actor interface.📝 Committable suggestion
Suggested change
🧰 Tools🪛 markdownlint-cli2 (0.22.1)[warning] 7-7: Headings should be surrounded by blank lines (MD022, blanks-around-headings) 🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||||||||||||
| - Dynamic apikey and emailpass authentication providers. | ||||||||||||
| - Decoupled command line runner integrations. | ||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Security Policy | ||
|
|
||
| ## Supported Versions | ||
|
|
||
| For pre-1.0 releases we support the latest release or the latest patch series (e.g., 0.1.x), and for 1.0+ we support the latest major release branch. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarify the supported versions policy. The phrase "the latest release or the latest patch series" is ambiguous—readers may not understand whether you support only the newest patch (e.g., 0.1.3 but not 0.1.2) or all patches in the latest series (all 0.1.x). Similarly, "latest major release branch" for 1.0+ could be misread as supporting only one major version even after newer majors are released. Consider rephrasing for clarity, for example:
🤖 Prompt for AI Agents |
||
|
|
||
| ## Reporting a Vulnerability | ||
|
|
||
| If you discover a security vulnerability within Hyperrr or any of its modules, please do not disclose it publicly. Report it directly by emailing security@hyperrr.org or opening a draft security advisory on GitHub. | ||
|
|
||
| We will acknowledge receipt of your report within 48 hours and work with you to patch the issue promptly. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package auth | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/GoHyperrr/mdk" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== go.mod =="
sed -n '1,200p' go.mod
echo
echo "== mdk dependency / replace directives =="
rg -n -C2 'github\.com/GoHyperrr/mdk|^\s*replace\s+.*mdk' go.mod go.sumRepository: GoHyperrr/auth Length of output: 802 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== filesystem check: ../mdk =="
if [ -d ../mdk ]; then
ls -la ../mdk | head -n 50
else
echo "MISSING: ../mdk directory does not exist"
fi
echo
echo "== mdk references in go.sum =="
rg -n 'github\.com/GoHyperrr/mdk' go.sum || echo "No go.sum entries found for github.com/GoHyperrr/mdk"Repository: GoHyperrr/auth Length of output: 215 Fix broken local module replacement for
🧰 Tools🪛 GitHub Actions: CI / 0_build.txt[error] 6-6: go vet failed: replacement directory ../mdk does not exist for module github.com/GoHyperrr/mdk@v0.0.0-20260605044506-3d2ab0d97ca9. 🪛 GitHub Actions: CI / build[error] 6-6: go vet ./... failed: actor.go:6:2: github.com/GoHyperrr/mdk@v0.0.0-20260605044506-3d2ab0d97ca9: replacement directory ../mdk does not exist 🪛 GitHub Check: build[failure] 6-6: 🪛 golangci-lint (2.12.2)[error] 6-6: could not import github.com/GoHyperrr/mdk (actor.go:6:2: github.com/GoHyperrr/mdk@v0.0.0-20260605044506-3d2ab0d97ca9: replacement directory ../mdk does not exist) (typecheck) 🤖 Prompt for AI AgentsSources: Linters/SAST tools, Pipeline failures |
||
| ) | ||
|
|
||
| // Actor is the concrete GORM database model representing a security principal. | ||
| // It implements the mdk.Actor interface. | ||
| type Actor struct { | ||
| ID string `gorm:"primaryKey" json:"id"` | ||
| Type mdk.ActorType `gorm:"index" json:"type"` | ||
| Name string `json:"name"` | ||
| Metadata mdk.JSONMap `gorm:"type:text" json:"metadata,omitempty"` | ||
| CreatedAt time.Time `json:"created_at"` | ||
| UpdatedAt time.Time `json:"updated_at"` | ||
| } | ||
|
|
||
| // Ensure Actor implements mdk.Actor. | ||
| var _ mdk.Actor = (*Actor)(nil) | ||
|
|
||
| func (a *Actor) GetID() string { | ||
| return a.ID | ||
| } | ||
|
|
||
| func (a *Actor) GetType() mdk.ActorType { | ||
| return a.Type | ||
| } | ||
|
|
||
| func (a *Actor) GetName() string { | ||
| return a.Name | ||
| } | ||
|
|
||
| func (a *Actor) GetMetadata() map[string]string { | ||
| return a.Metadata | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ package emailpass | |
| import ( | ||
| "time" | ||
|
|
||
| "github.com/GoHyperrr/auth" | ||
| "github.com/GoHyperrr/mdk" | ||
| "gorm.io/gorm" | ||
| ) | ||
|
|
@@ -13,15 +14,15 @@ type User struct { | |
| Email string `gorm:"uniqueIndex;not null" json:"email"` | ||
| PasswordHash string `gorm:"not null" json:"-"` | ||
| ActorID string `gorm:"not null" json:"actor_id"` | ||
| Actor mdk.Actor `gorm:"foreignKey:ActorID" json:"actor"` | ||
| Actor auth.Actor `gorm:"foreignKey:ActorID" json:"actor"` | ||
|
Comment on lines
16
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Files containing emailpass/model.go and emailpass/handlers.go =="
ls -la emailpass || true
git ls-files | rg -n '^emailpass/(model\.go|handlers\.go)$' || true
echo
echo "== emailpass/model.go =="
sed -n '1,120p' emailpass/model.go
echo
echo "== emailpass/handlers.go (or similarly named handlers) =="
if [ -f emailpass/handlers.go ]; then
sed -n '1,240p' emailpass/handlers.go
else
git ls-files | rg '^emailpass/.*handlers\.go$' || true
fi
echo
echo "== Search for Preload(\"Actor\") and references to user.Actor / ActorID =="
rg -n --hidden --no-ignore-vcs 'Preload\("Actor"\)|Preload\(\"Actor\"\)|\.Actor\b|GenerateToken|Login\(' emailpass || true
echo
echo "== Search for GenerateToken implementation =="
rg -n --hidden --no-ignore-vcs 'func .*GenerateToken|GenerateToken\(' . || trueRepository: GoHyperrr/auth Length of output: 4700 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== emailpass/graphql.go =="
sed -n '1,220p' emailpass/graphql.go
echo
echo "== jwt/jwt.go =="
if [ -f jwt/jwt.go ]; then
sed -n '1,220p' jwt/jwt.go
else
git ls-files | rg -n '^jwt/.*\.go$' || true
fi
echo
echo "== emailpass/module.go =="
sed -n '1,240p' emailpass/module.go
echo
echo "== Search: returns &user.Actor / user.Actor usage =="
rg -n --hidden --no-ignore-vcs '&user\.Actor|\buser\.Actor\b' emailpass || true
echo
echo "== Search: actor_id constraints / foreign keys =="
rg -n --hidden --no-ignore-vcs 'ActorID|foreignKey|constraint|OnDelete|references' emailpass || trueRepository: GoHyperrr/auth Length of output: 9363 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Find auth.Actor type =="
git ls-files | rg -n '^.*auth/.*\.go$' || true
rg -n --hidden --no-ignore-vcs 'type Actor struct|func \(.*\) GetID\(\)|func \(.*\) GetType\(\)' . || true
echo
echo "== Read auth.Actor definition =="
# Try likely filenames
for f in $(git ls-files | rg '^auth/.*\.go$' || true); do
rg -n --hidden --no-ignore-vcs 'type Actor struct' "$f" >/dev/null 2>&1 && echo "$f"
done | head -n 20
# Print the first match file for Actor struct
actor_file="$(git ls-files | rg '^auth/.*\.go$' | while read -r f; do rg -l --hidden --no-ignore-vcs 'type Actor struct' "$f" >/dev/null && echo "$f"; done | head -n 1)"
if [ -n "${actor_file:-}" ] && [ -f "$actor_file" ]; then
echo
echo "== $actor_file (snippet) =="
nl -ba "$actor_file" | sed -n '1,220p'
else
echo "Could not locate auth/Actor struct file under auth/ directory."
fi
echo
echo "== Find where validate_actor workflow step is used =="
rg -n --hidden --no-ignore-vcs '"auth\.validate_actor"|validate_actor' . || true
echo
echo "== Search for token validation pipeline in runtime =="
rg -n --hidden --no-ignore-vcs 'ValidateToken|TokenValidator|Authenticate|auth\.emailpass' . || trueRepository: GoHyperrr/auth Length of output: 256 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== actor.go =="
nl -ba actor.go | sed -n '1,120p'
echo
echo "== Search for Login / GenerateToken usage in auth flow =="
rg -n --hidden --no-ignore-vcs 'LoginResolver|Store\(\)\.GenerateToken|GenerateToken\(|ValidateToken\(|TokenValidator|Authenticate|auth\.emailpass|emailpass\.Login|emailpass\.LoginResolver' . || true
echo
echo "== Search for mdk runtime authentication / middleware hook =="
rg -n --hidden --no-ignore-vcs 'Authenticate|token.*validate|ValidateToken|TokenValidator' . || trueRepository: GoHyperrr/auth Length of output: 134 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== actor.go =="
cat -n actor.go | sed -n '1,140p'
echo
echo "== Search: Login/GenerateToken call sites =="
rg -n --hidden --no-ignore-vcs 'emailpass/|LoginResolver|emailpass\.Login|GenerateToken\(|GenerateToken\(' . || true
echo
echo "== Search: token validation / auth middleware =="
rg -n --hidden --no-ignore-vcs 'ValidateToken|TokenValidator|Authenticate|auth\.emailpass' . || true
echo
echo "== Search: where ValidateToken is called =="
rg -n --hidden --no-ignore-vcs '\.ValidateToken\(' . || trueRepository: GoHyperrr/auth Length of output: 2665 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Search for validate_actor usage =="
rg -n --hidden --no-ignore-vcs 'validate_actor|ValidateActorStep|auth\.validate_actor' . || true
echo
echo "== Search for checks on empty actor_id / ActorID =="
rg -n --hidden --no-ignore-vcs 'ActorID.*(==|!=|empty|""|not null)|actor_id.*(==|!=|empty|"" )|claims\.ActorID' . || true
echo
echo "== Search for GetID() validation =="
rg -n --hidden --no-ignore-vcs '\.GetID\(\)' . || true
echo
echo "== Search for JWT claim parsing usage =="
rg -n --hidden --no-ignore-vcs 'ActorType|ActorID|RegisteredClaims|claims\.' jwt . emailpass . || trueRepository: GoHyperrr/auth Length of output: 5205 Fix emailpass.User.Actor association to prevent issuing JWTs with empty actor_id/type
Suggested direction type User struct {
ID string `gorm:"primaryKey" json:"id"`
Email string `gorm:"uniqueIndex;not null" json:"email"`
PasswordHash string `gorm:"not null" json:"-"`
ActorID string `gorm:"not null" json:"actor_id"`
- Actor auth.Actor `gorm:"foreignKey:ActorID" json:"actor"`
+ Actor *auth.Actor `gorm:"foreignKey:ActorID" json:"actor"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}Also reject login when the preloaded actor is nil (or when 🤖 Prompt for AI Agents |
||
| CreatedAt time.Time `json:"created_at"` | ||
| UpdatedAt time.Time `json:"updated_at"` | ||
| DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` | ||
| } | ||
|
|
||
| type AuthResponse struct { | ||
| Token string `json:"token"` | ||
| Actor *mdk.Actor `json:"actor"` | ||
| Token string `json:"token"` | ||
| Actor mdk.Actor `json:"actor"` | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -15,3 +15,5 @@ require ( | |||
| github.com/jinzhu/now v1.1.5 // indirect | ||||
| golang.org/x/text v0.37.0 // indirect | ||||
| ) | ||||
|
|
||||
| replace github.com/GoHyperrr/mdk => ../mdk | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove committed local Line 19 pins Suggested change-replace github.com/GoHyperrr/mdk => ../mdk📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: GoHyperrr/auth
Length of output: 146
🏁 Script executed:
Repository: GoHyperrr/auth
Length of output: 3573
🌐 Web query:
actions/checkout persist-credentials default value💡 Result:
The default value of the actions/checkout input
persist-credentialsis true.[1][2] This option controls whether the authentication token used to fetch the repository is persisted in the local git configuration so subsequent authenticated git commands work; it can be disabled withpersist-credentials: false.[1][2]Citations:
Pin
actions/checkoutto commit SHAs and disable persisted credentials (CI security)..github/workflows/ci.ymllines 16 and 18, both steps use mutableactions/checkout@v4; pin to the full commit SHA.with: persist-credentials: false;actions/checkoutdefaults this totrue, persisting the token in git config.GoHyperrr/mdkcheckout usesref: ${{ github.head_ref || github.ref_name }}, coupling the ref to the auth repo’s branch name and risking failures when that branch doesn’t exist inGoHyperrr/mdk.Proposed fix
🧰 Tools
🪛 zizmor (1.25.2)
[error] 16-16: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)
(unpinned-uses)
[error] 18-18: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)
(unpinned-uses)
🤖 Prompt for AI Agents
Source: Linters/SAST tools