Skip to content

Commit d1d28f2

Browse files
authored
Merge pull request #124 from trydirect/dev
enrich service catalog, nginx proxy auto inject docker hub image
2 parents e08acb0 + 9196a10 commit d1d28f2

24 files changed

Lines changed: 1155 additions & 78 deletions

.sqlx/query-32d118e607db4364979c52831e0c30a215779928a041ef51e93383e93288aac2.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-8ec4c1e77a941efe4c1c36e26c5e1dfcb0e7769f0333d2acf7d6e0fb97ca12dc.json renamed to .sqlx/query-4048935127dfdfa4f8d1c7ec9137149b736702a008e920373c139d5cc8f228a5.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-b8296183bd28695d3a7574e57db445dc1f4b2d659a3805f92f6f5f83b562266b.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-7b6c7e798237d0c08b7c1126d7044df13c46ef2eb373398a535090edf738cb5a.json renamed to .sqlx/query-e0bc560df5637788c7096c0bf0535cc601af9ca4a06bd87100cd68a251431618.json

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DROP INDEX IF EXISTS idx_cloud_user_name;
2+
ALTER TABLE cloud DROP COLUMN IF EXISTS name;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Add a human-friendly name to cloud credentials so users can reference them
2+
-- by name (e.g. `stacker deploy --key my-hetzner`) instead of by provider.
3+
ALTER TABLE cloud ADD COLUMN name VARCHAR(100);
4+
5+
-- Backfill existing rows: default name = "{provider}-{id}" (e.g. "htz-4")
6+
UPDATE cloud SET name = provider || '-' || id WHERE name IS NULL;
7+
8+
-- Make name NOT NULL after backfill
9+
ALTER TABLE cloud ALTER COLUMN name SET NOT NULL;
10+
11+
-- Unique per user: a user can't have two cloud keys with the same name
12+
CREATE UNIQUE INDEX idx_cloud_user_name ON cloud (user_id, name);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- Revert client role Casbin mappings
2+
DELETE FROM public.casbin_rule WHERE ptype = 'g' AND v0 = 'client' AND v1 = 'group_anonymous';
3+
DELETE FROM public.casbin_rule WHERE ptype = 'p' AND v0 = 'client' AND v1 = '/api/v1/agent/register' AND v2 = 'POST';
4+
DELETE FROM public.casbin_rule WHERE ptype = 'p' AND v0 = 'client' AND v1 = '/api/v1/agent/commands/wait/:deployment_hash' AND v2 = 'GET';
5+
DELETE FROM public.casbin_rule WHERE ptype = 'p' AND v0 = 'client' AND v1 = '/api/v1/agent/commands/report' AND v2 = 'POST';
6+
DELETE FROM public.casbin_rule WHERE ptype = 'p' AND v0 = 'client' AND v1 = '/project/:id/deploy' AND v2 = 'POST';
7+
DELETE FROM public.casbin_rule WHERE ptype = 'p' AND v0 = 'client' AND v1 = '/project/:id/deploy/:cloud_id' AND v2 = 'POST';
8+
DELETE FROM public.casbin_rule WHERE ptype = 'p' AND v0 = 'client' AND v1 = '/project/:id/compose' AND v2 = 'GET';
9+
DELETE FROM public.casbin_rule WHERE ptype = 'p' AND v0 = 'client' AND v1 = '/project/:id/compose' AND v2 = 'POST';
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
-- Fix 403 on agent registration when using HMAC auth (client role).
2+
-- The HMAC middleware now sets subject = "client" (previously was the numeric
3+
-- client_id which had no Casbin mapping at all).
4+
-- Ensure the "client" role inherits from group_anonymous (like group_user/group_admin).
5+
6+
INSERT INTO public.casbin_rule (ptype, v0, v1, v2, v3, v4, v5)
7+
VALUES ('g', 'client', 'group_anonymous', '', '', '', '')
8+
ON CONFLICT ON CONSTRAINT unique_key_sqlx_adapter DO NOTHING;
9+
10+
-- Safety: ensure agent register is accessible by group_anonymous
11+
INSERT INTO public.casbin_rule (ptype, v0, v1, v2, v3, v4, v5)
12+
VALUES ('p', 'group_anonymous', '/api/v1/agent/register', 'POST', '', '', '')
13+
ON CONFLICT ON CONSTRAINT unique_key_sqlx_adapter DO NOTHING;
14+
15+
-- Safety: ensure client has explicit access to agent register
16+
INSERT INTO public.casbin_rule (ptype, v0, v1, v2, v3, v4, v5)
17+
VALUES ('p', 'client', '/api/v1/agent/register', 'POST', '', '', '')
18+
ON CONFLICT ON CONSTRAINT unique_key_sqlx_adapter DO NOTHING;
19+
20+
-- Grant client access to other agent endpoints (wait, report, enqueue)
21+
INSERT INTO public.casbin_rule (ptype, v0, v1, v2, v3, v4, v5)
22+
VALUES ('p', 'client', '/api/v1/agent/commands/wait/:deployment_hash', 'GET', '', '', '')
23+
ON CONFLICT ON CONSTRAINT unique_key_sqlx_adapter DO NOTHING;
24+
25+
INSERT INTO public.casbin_rule (ptype, v0, v1, v2, v3, v4, v5)
26+
VALUES ('p', 'client', '/api/v1/agent/commands/report', 'POST', '', '', '')
27+
ON CONFLICT ON CONSTRAINT unique_key_sqlx_adapter DO NOTHING;
28+
29+
-- Grant client access to deploy-related endpoints that HMAC clients need
30+
INSERT INTO public.casbin_rule (ptype, v0, v1, v2, v3, v4, v5)
31+
VALUES ('p', 'client', '/project/:id/deploy', 'POST', '', '', '')
32+
ON CONFLICT ON CONSTRAINT unique_key_sqlx_adapter DO NOTHING;
33+
34+
INSERT INTO public.casbin_rule (ptype, v0, v1, v2, v3, v4, v5)
35+
VALUES ('p', 'client', '/project/:id/deploy/:cloud_id', 'POST', '', '', '')
36+
ON CONFLICT ON CONSTRAINT unique_key_sqlx_adapter DO NOTHING;
37+
38+
INSERT INTO public.casbin_rule (ptype, v0, v1, v2, v3, v4, v5)
39+
VALUES ('p', 'client', '/project/:id/compose', 'GET', '', '', '')
40+
ON CONFLICT ON CONSTRAINT unique_key_sqlx_adapter DO NOTHING;
41+
42+
INSERT INTO public.casbin_rule (ptype, v0, v1, v2, v3, v4, v5)
43+
VALUES ('p', 'client', '/project/:id/compose', 'POST', '', '', '')
44+
ON CONFLICT ON CONSTRAINT unique_key_sqlx_adapter DO NOTHING;

src/bin/stacker.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ enum StackerCommands {
9191
/// Name of saved cloud credential to reuse (overrides deploy.cloud.key in stacker.yml)
9292
#[arg(long, value_name = "KEY_NAME")]
9393
key: Option<String>,
94+
/// ID of saved cloud credential to reuse (from `stacker list clouds`)
95+
#[arg(long, value_name = "CLOUD_ID")]
96+
key_id: Option<i32>,
9497
/// Name of saved server to reuse (overrides deploy.cloud.server in stacker.yml)
9598
#[arg(long, value_name = "SERVER_NAME")]
9699
server: Option<String>,
@@ -100,6 +103,12 @@ enum StackerCommands {
100103
/// Disable automatic progress watching after deploy
101104
#[arg(long)]
102105
no_watch: bool,
106+
/// Persist server details into stacker.yml after deploy (for redeploy)
107+
#[arg(long)]
108+
lock: bool,
109+
/// Skip server pre-check; force fresh cloud provision even if deploy.server exists
110+
#[arg(long)]
111+
force_new: bool,
103112
},
104113
/// Show container logs
105114
Logs {
@@ -207,6 +216,12 @@ enum ListCommands {
207216
#[arg(long)]
208217
json: bool,
209218
},
219+
/// List saved cloud credentials
220+
Clouds {
221+
/// Output in JSON format
222+
#[arg(long)]
223+
json: bool,
224+
},
210225
}
211226

212227
#[derive(Debug, Subcommand)]
@@ -306,6 +321,16 @@ enum ConfigCommands {
306321
#[arg(long, default_value_t = true)]
307322
interactive: bool,
308323
},
324+
/// Persist deployment lock into stacker.yml (writes deploy.server from last deploy)
325+
Lock {
326+
#[arg(long, value_name = "FILE")]
327+
file: Option<String>,
328+
},
329+
/// Remove deploy.server section from stacker.yml (allows fresh cloud provision)
330+
Unlock {
331+
#[arg(long, value_name = "FILE")]
332+
file: Option<String>,
333+
},
309334
/// Guided setup helpers
310335
Setup {
311336
#[command(subcommand)]
@@ -500,9 +525,12 @@ fn get_command(
500525
force_rebuild,
501526
project,
502527
key,
528+
key_id,
503529
server,
504530
watch,
505531
no_watch,
532+
lock,
533+
force_new,
506534
} => Box::new(
507535
stacker::console::commands::cli::deploy::DeployCommand::new(
508536
target,
@@ -511,7 +539,10 @@ fn get_command(
511539
force_rebuild,
512540
)
513541
.with_remote_overrides(project, key, server)
514-
.with_watch(watch, no_watch),
542+
.with_key_id(key_id)
543+
.with_watch(watch, no_watch)
544+
.with_lock(lock)
545+
.with_force_new(force_new),
515546
),
516547
StackerCommands::Logs {
517548
service,
@@ -540,6 +571,12 @@ fn get_command(
540571
ConfigCommands::Fix { file, interactive } => Box::new(
541572
stacker::console::commands::cli::config::ConfigFixCommand::new(file, interactive),
542573
),
574+
ConfigCommands::Lock { file } => Box::new(
575+
stacker::console::commands::cli::config::ConfigLockCommand::new(file),
576+
),
577+
ConfigCommands::Unlock { file } => Box::new(
578+
stacker::console::commands::cli::config::ConfigUnlockCommand::new(file),
579+
),
543580
ConfigCommands::Setup { command } => match command {
544581
ConfigSetupCommands::Cloud { file } => Box::new(
545582
stacker::console::commands::cli::config::ConfigSetupCloudCommand::new(file),
@@ -590,6 +627,9 @@ fn get_command(
590627
ListCommands::SshKeys { json } => Box::new(
591628
stacker::console::commands::cli::list::ListSshKeysCommand::new(json),
592629
),
630+
ListCommands::Clouds { json } => Box::new(
631+
stacker::console::commands::cli::list::ListCloudsCommand::new(json),
632+
),
593633
},
594634
StackerCommands::SshKey { command: ssh_cmd } => match ssh_cmd {
595635
SshKeyCommands::Generate { server_id, save_to } => Box::new(

0 commit comments

Comments
 (0)