-
Notifications
You must be signed in to change notification settings - Fork 383
Record which resources a control plane owns #5190
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
Closed
bhagyasakalanka
wants to merge
4
commits into
thunder-id:main
from
bhagyasakalanka:pr04-managedresource
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8502f66
Derive declarative placeholder names in one place
bhagyasakalanka 87a78fa
Resolve a credential reference through a secret provider
bhagyasakalanka 52cd969
Read the per-request deployment id from one place
bhagyasakalanka 1745563
Record which resources a control plane owns
bhagyasakalanka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| /* | ||
| * Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com). | ||
| * | ||
| * WSO2 LLC. licenses this file to you under the Apache License, | ||
| * Version 2.0 (the "License"); you may not use this file except | ||
| * in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package entity | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
|
|
||
| "github.com/thunder-id/thunderid/internal/system/cryptolib" | ||
| "github.com/thunder-id/thunderid/internal/system/secretresolver" | ||
| ) | ||
|
|
||
| // serveKVHash stands up a secret provider holding one hash backed secret. | ||
| func serveKVHash(t *testing.T, name string, hash cryptolib.Credential) { | ||
| t.Helper() | ||
| srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { | ||
| _ = json.NewEncoder(w).Encode(map[string]interface{}{"secrets": map[string]interface{}{ | ||
| name: map[string]interface{}{ | ||
| "kind": "hash", | ||
| "value": hash.Hash, | ||
| "algorithm": string(hash.Algorithm), | ||
| "parameters": map[string]interface{}{ | ||
| "salt": hash.Parameters.Salt, | ||
| "iterations": hash.Parameters.Iterations, | ||
| "keySize": hash.Parameters.KeySize, | ||
| }, | ||
| }, | ||
| }}) | ||
| })) | ||
| t.Cleanup(srv.Close) | ||
|
|
||
| previous := secretresolver.Default() | ||
| r := secretresolver.New(secretresolver.Config{BaseURL: srv.URL}) | ||
| if err := r.LoadAll(t.Context()); err != nil { | ||
| t.Fatalf("load: %v", err) | ||
| } | ||
| secretresolver.SetDefault(r) | ||
| t.Cleanup(func() { secretresolver.SetDefault(previous) }) | ||
| } | ||
|
|
||
| // hashOf produces a credential the way the control plane would. | ||
| func hashOf(t *testing.T, plaintext string) cryptolib.Credential { | ||
| t.Helper() | ||
| svc, err := cryptolib.Initialize(cryptolib.HashConfig{ | ||
| Algorithm: cryptolib.PBKDF2, SaltSize: 16, Iterations: 1000, KeySize: 32, | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("hash service: %v", err) | ||
| } | ||
| cred, err := svc.Generate([]byte(plaintext)) | ||
| if err != nil { | ||
| t.Fatalf("generate: %v", err) | ||
| } | ||
| return cred | ||
| } | ||
|
|
||
| func TestCredentialReference_ResolvesAPromotedCredentialFromTheSecretProvider(t *testing.T) { | ||
| const plaintext = "the-client-secret" | ||
| hash := hashOf(t, plaintext) | ||
| serveKVHash(t, "MY_APP_CLIENT_SECRET", hash) | ||
|
|
||
| // The database holds only a reference: the credential itself never reached this deployment's DB. | ||
| ref, usable := credentialReference(StoredCredential{Value: "secret:MY_APP_CLIENT_SECRET"}) | ||
| if !usable { | ||
| t.Fatal("a resolvable reference must be usable") | ||
| } | ||
| if ref.Hash != hash.Hash || ref.Parameters.Salt != hash.Parameters.Salt { | ||
| t.Fatalf("the reference should carry the provider's hash and parameters, got %+v", ref) | ||
| } | ||
| // The parameters come from wherever the credential was made, not from this server's configuration. | ||
| if ref.Parameters.Iterations != hash.Parameters.Iterations { | ||
| t.Fatalf("iterations should come from the provider, got %d", ref.Parameters.Iterations) | ||
| } | ||
| } | ||
|
|
||
| func TestCredentialReference_LeavesANativeCredentialAlone(t *testing.T) { | ||
| hash := hashOf(t, "created-here") | ||
|
|
||
| // A credential created on this deployment is stored normally and must keep working unchanged. | ||
| ref, usable := credentialReference(StoredCredential{ | ||
| StorageAlgo: hash.Algorithm, | ||
| Value: hash.Hash, | ||
| StorageAlgoParams: hash.Parameters, | ||
| }) | ||
| if !usable || ref.Hash != hash.Hash || ref.Algorithm != hash.Algorithm { | ||
| t.Fatalf("a stored credential should be used as it stands, got %+v usable=%v", ref, usable) | ||
| } | ||
| } | ||
|
|
||
| func TestCredentialReference_RejectsAnUnresolvableReference(t *testing.T) { | ||
| serveKVHash(t, "SOMETHING_ELSE", hashOf(t, "x")) | ||
|
|
||
| // An absent secret must reject rather than pass: treating it as a match would let any value in. | ||
| if _, usable := credentialReference(StoredCredential{Value: "secret:NOT_IN_THE_PROVIDER"}); usable { | ||
| t.Fatal("an unresolvable reference must not be usable") | ||
| } | ||
| } | ||
|
|
||
| func TestHashPlaintextCredentials_KeepsAReferenceAsItIs(t *testing.T) { | ||
| const plaintext = "the-client-secret" | ||
| hash := hashOf(t, plaintext) | ||
| serveKVHash(t, "MY_APP_CLIENT_SECRET", hash) | ||
|
|
||
| svc := &entityService{hashService: mustHashService(t)} | ||
| stored, err := svc.hashPlaintextCredentials(json.RawMessage(`{"clientSecret":"secret:MY_APP_CLIENT_SECRET"}`)) | ||
| if err != nil { | ||
| t.Fatalf("hash credentials: %v", err) | ||
| } | ||
|
|
||
| var creds map[string][]StoredCredential | ||
| if err := json.Unmarshal(stored, &creds); err != nil { | ||
| t.Fatalf("unmarshal: %v", err) | ||
| } | ||
| // Hashing the reference text would store the hash of "secret:..." and reject every authentication. | ||
| if got := creds["clientSecret"][0].Value; got != "secret:MY_APP_CLIENT_SECRET" { | ||
| t.Fatalf("the reference should be stored verbatim, got %q", got) | ||
| } | ||
|
|
||
| // And the reference still resolves to the provider's hash, so the real secret verifies. | ||
| ref, usable := credentialReference(creds["clientSecret"][0]) | ||
| if !usable { | ||
| t.Fatal("the stored reference must resolve") | ||
| } | ||
| ok, err := mustHashService(t).Verify([]byte(plaintext), ref) | ||
| if err != nil || !ok { | ||
| t.Fatalf("the promoted credential should verify, ok=%v err=%v", ok, err) | ||
| } | ||
| } | ||
|
|
||
| // mustHashService builds the hashing this server would be configured with. | ||
| func mustHashService(t *testing.T) cryptolib.HashServiceInterface { | ||
| t.Helper() | ||
| svc, err := cryptolib.Initialize(cryptolib.HashConfig{ | ||
| Algorithm: cryptolib.PBKDF2, SaltSize: 16, Iterations: 1000, KeySize: 32, | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("hash service: %v", err) | ||
| } | ||
| return svc | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: thunder-id/thunderid
Length of output: 8632
🏁 Script executed:
Repository: thunder-id/thunderid
Length of output: 50377
🏁 Script executed:
Repository: thunder-id/thunderid
Length of output: 10180
🏁 Script executed:
Repository: thunder-id/thunderid
Length of output: 46318
🏁 Script executed:
Repository: thunder-id/thunderid
Length of output: 21977
🏁 Script executed:
Repository: thunder-id/thunderid
Length of output: 15008
Add upgrade migrations for
MANAGED_RESOURCEconfigdb/postgres.sqlandconfigdb/sqlite.sqlrun only during database initialization. Existing databases therefore do not receiveMANAGED_RESOURCE. When control-plane management usesmanagedresourcequeries, PostgreSQL and SQLite can fail with a missing-table error. Add upgrade migrations for both engines.📍 Affects 2 files
backend/dbscripts/configdb/postgres.sql#L365-L375(this comment)backend/dbscripts/configdb/sqlite.sql#L365-L375🤖 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.
Not applicable as asked. This repository has no migration mechanism:
backend/dbscriptsholds only the full schema per database and there is no upgrade or versioning convention to add a step to.MANAGED_RESOURCEfollows that existing convention. Introducing migrations is a real gap but a separate decision, not something to invent inside this PR.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.
Rate Limit Exceeded
@bhagyasakalankahave exceeded the limit for the number of chat messages per hour. Please wait 42 minutes and 21 seconds before sending another message.