Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/self-host/config-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ The CDK app turns the config into environment variables on the gateway, streamin
|---|---|
| `APP_URL`, `API_URL` | Your hostname, when you have one |
| `PUBLIC_URL_PARAMETER` | The SSM parameter that holds the CloudFront URL, when you have no domain |
| `SELF_HOSTED` | `1` on every self-hosted install: links never fall back to CoderHelm's hosted addresses, and support goes to `SUPPORT_INBOX` |
| `SITE_URL` | `siteUrl` |
| `CODERHELM_ACCOUNT_ID` | `account` (the account teams' read-only roles trust) |
| `LOG_READER_TEMPLATE_URL` | `logReaderTemplateUrl` |
Expand Down
6 changes: 6 additions & 0 deletions docs/self-host/email.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ and deploy again. Turning it on before the identity is verified makes the deploy
## Templates

The email templates are created by the email stack with your URLs filled in. `email.logoUrl` and `email.privacyUrl` change the header logo and the footer link.

## Links in emails and messages

Every link CoderHelm sends from your install points at your install: emails (run results, invites, approvals, the weekly summary and its unsubscribe link), Slack and Teams cards, Jira comments and GitHub comments all use your own address. The header logo loads from your install (`<your address>/favicon.svg`) unless you set `email.logoUrl`, so opening an email never calls CoderHelm's servers. Support and "reply to unsubscribe" go to `email.supportInbox` (by default `email.from`), never to CoderHelm support. The only coderhelm.com links left are the public docs on docs.coderhelm.com.

If the install doesn't know its own address (no `APP_URL` and `API_URL`, and the CloudFront address not yet readable from SSM), links stay relative rather than pointing anywhere else, the services log an error at start, and **Settings, then Setup** fails **Web address answers** until a deploy sets it.
3 changes: 3 additions & 0 deletions infra/lib/service-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export function serviceEnvironment(cfg: ResolvedConfig, account: string): Record
// Self-hosted installs: which release this is (Settings → System), and
// the updater the system routes ask. The hosted deployment has neither.
if (cfg.layout === "single-origin") {
// A self-hosted install: its links never fall back to the hosted
// addresses, and support goes to its own inbox (public_urls.rs).
env.SELF_HOSTED = "1";
Object.assign(env, stampEnvironment(releaseStamp(cfg)));
// Whether "Sign in with Google" is on (Settings, then Setup checks it).
env.GOOGLE_SIGN_IN = cfg.integrations.googleSignIn ? "true" : "false";
Expand Down
5 changes: 5 additions & 0 deletions infra/test/synth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ test("the manifest landing: self-host only, may write only this install's secret
const api = t["coderhelm-prod-api"];
const gw = envOf(api, "coderhelm-prod-gateway");
assert.equal(gw.SETUP_ENDPOINTS, "1");
// Every service knows it is self-hosted, so no link falls back to the hosted addresses.
for (const [stack, fn] of [["coderhelm-prod-api", "coderhelm-prod-gateway"], ["coderhelm-prod-worker", "coderhelm-prod-worker"]] as const) {
assert.equal(envOf(t[stack], fn).SELF_HOSTED, "1", fn);
}
const policies = JSON.stringify(api.findResources("AWS::IAM::Policy"));
assert.ok(policies.includes("SetupStoresGithubAppKeys"));
assert.ok(policies.includes("secret:coderhelm/prod/secrets-??????"), "only this install's secret");
Expand All @@ -338,6 +342,7 @@ test("the manifest landing: self-host only, may write only this install's secret
const hostedCfg = loadConfigFile(path.join(INFRA, "config", "hosted.prod.json"), { CDK_DEFAULT_ACCOUNT: "654654210434" });
const hosted = synth(hostedCfg, zoneContext("654654210434", "us-east-1", "coderhelm.com"));
assert.equal(envOf(hosted["coderhelm-prod-api"], "coderhelm-prod-gateway").SETUP_ENDPOINTS, undefined);
assert.equal(envOf(hosted["coderhelm-prod-api"], "coderhelm-prod-gateway").SELF_HOSTED, undefined);
assert.ok(!JSON.stringify(hosted["coderhelm-prod-api"].findResources("AWS::IAM::Policy")).includes("SetupStoresGithubAppKeys"));
// The install guide reads launch/latest.json from the public bucket in the browser.
hosted["coderhelm-prod-log-analyzer"].hasResourceProperties("AWS::S3::Bucket", {
Expand Down
4 changes: 3 additions & 1 deletion lambda/log-analyzer/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
MODEL_ID = os.environ.get("MODEL_ID", "claude-sonnet-4-6")
CODERHELM_ACCOUNT_ID = os.environ["CODERHELM_ACCOUNT_ID"]
LOOKBACK_HOURS = int(os.environ.get("LOOKBACK_HOURS", "24"))
DASHBOARD_URL = os.environ.get("DASHBOARD_URL", "https://app.coderhelm.com")
# This deployment's dashboard (the deploy always sets it); never the hosted
# dashboard, which a self-hosted install's teams can't sign in to.
DASHBOARD_URL = os.environ["DASHBOARD_URL"].rstrip("/")
# Team usage counters (empty: usage isn't counted).
ANALYTICS_TABLE = os.environ.get("ANALYTICS_TABLE_NAME", "")

Expand Down
1 change: 1 addition & 0 deletions lambda/tests/test_log_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
def load_handler(model_id):
os.environ.update(
CODERHELM_ACCOUNT_ID="000000000000",
DASHBOARD_URL="https://coderhelm.example.com",
MODEL_ID=model_id,
AWS_DEFAULT_REGION="us-east-1",
)
Expand Down
12 changes: 8 additions & 4 deletions services/common/src/agent_policy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ pub fn next_id() -> String {
.to_string()
}

/// Where the dashboard lives (links in Slack, Teams and email).
pub const DASHBOARD_URL: &str = "https://app.coderhelm.com";
/// Where the gateway answers signed approval links.
pub const API_URL: &str = "https://api.coderhelm.com";
/// Where this install's dashboard lives (links in Slack, Teams and email).
pub fn dashboard_url() -> &'static str {
crate::public_urls::app_url_from_env()
}
/// Where this install's gateway answers signed approval links.
pub fn api_url() -> &'static str {
crate::public_urls::api_url_from_env()
}
56 changes: 52 additions & 4 deletions services/common/src/agent_policy/notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::notify::{Block, Button, Message, Size, Text, Tone};
use super::approvals::Approval;
use super::links::{self, Channel, LinkClaims};
use super::signin::Prompt;
use super::{API_URL, DASHBOARD_URL};
use super::{api_url, dashboard_url};

/// A signed link to an approval for a channel (or a person, for email).
pub fn approval_link(
Expand All @@ -36,7 +36,8 @@ pub fn approval_link(
},
);
format!(
"{API_URL}/agent-approvals/link?t={}&do={}",
"{}/agent-approvals/link?t={}&do={}",
api_url(),
urlencoding::encode(&token),
urlencoding::encode(action)
)
Expand All @@ -45,7 +46,8 @@ pub fn approval_link(
/// The dashboard page for an approval (signed in).
pub fn approval_page(a: &Approval) -> String {
format!(
"{DASHBOARD_URL}/settings/agents?approval={}",
"{}/settings/agents?approval={}",
dashboard_url(),
urlencoding::encode(&a.id)
)
}
Expand Down Expand Up @@ -134,7 +136,7 @@ pub fn sign_in_message(p: &Prompt, run_id: &str) -> Message {
} else {
"Connect"
},
format!("{DASHBOARD_URL}{}", p.link_path),
format!("{}{}", dashboard_url(), p.link_path),
)],
full_width: false,
}
Expand Down Expand Up @@ -196,6 +198,52 @@ mod tests {
}
}

/// A self-hosted install's approval cards and sign-in prompts link to
/// the install, in every channel, never to the hosted service.
#[test]
fn a_self_hosted_install_links_to_itself() {
use crate::public_urls::{hosted_mentions, pretend_self_hosted, EXAMPLE_SELF_HOST};
pretend_self_hosted();
let a = card();
let p = super::super::signin::prompt(
"figma",
"Figma",
super::super::signin::Need::Personal,
true,
"read this file",
);
let messages = [
approval_message("s3cret", "TEAM#1", &a, Channel::Slack),
approval_message("s3cret", "TEAM#1", &a, Channel::Teams),
sign_in_message(&p, "run-1"),
];
let mut out = vec![
approval_page(&a),
approval_link(
"s3cret",
"TEAM#1",
&a,
Channel::Email,
"ada@example.org",
"approve",
),
];
for m in &messages {
for b in &m.buttons {
assert!(b.url.starts_with(EXAMPLE_SELF_HOST), "{}", b.url);
}
for kind in crate::notify::ChannelKind::ALL {
out.push(kind.render(m).to_string());
}
}
crate::public_urls::override_for_this_thread(None);
for o in &out {
assert_eq!(hosted_mentions(o), Vec::<String>::new(), "{o}");
}
assert!(out[0].starts_with(EXAMPLE_SELF_HOST));
assert!(out[1].starts_with(EXAMPLE_SELF_HOST));
}

#[test]
fn sign_in_messages_link_to_the_dashboard() {
let p = super::super::signin::prompt(
Expand Down
2 changes: 2 additions & 0 deletions services/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ pub mod rewards;
pub mod run_fail;
/// Run statuses; which ones a person set; closing and reopening a run.
pub mod run_status;
#[cfg(test)]
mod selfhost_links;
pub mod skill_apply;
pub mod skill_compat;
pub mod skills;
Expand Down
13 changes: 12 additions & 1 deletion services/common/src/mcp_remote/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ pub fn registration_request(a: &AuthServer, redirect_uri: &str, scopes: &[String
};
let mut body = serde_json::json!({
"client_name": CLIENT_NAME,
"client_uri": "https://coderhelm.com",
// The install that asks: the callback's origin (a self-hosted
// install's own address, never the hosted site).
"client_uri": origin_of(redirect_uri),
"redirect_uris": [redirect_uri],
"grant_types": ["authorization_code", "refresh_token"],
"response_types": ["code"],
Expand All @@ -207,6 +209,14 @@ pub fn registration_request(a: &AuthServer, redirect_uri: &str, scopes: &[String
.header("Accept", "application/json")
}

/// `https://host[:port]` of a URL, or the URL itself when it has no host.
fn origin_of(u: &str) -> String {
match url::Url::parse(u) {
Ok(p) if p.host_str().is_some() => p.origin().ascii_serialization(),
_ => u.to_string(),
}
}

/// Reads a registration reply.
pub fn parse_registration(r: &HttpResponse) -> Result<Client, String> {
let doc = r.json().unwrap_or_default();
Expand Down Expand Up @@ -615,6 +625,7 @@ mod tests {
let body: serde_json::Value = serde_json::from_slice(r.body.as_ref().unwrap()).unwrap();
assert_eq!(body["token_endpoint_auth_method"], "none");
assert_eq!(body["redirect_uris"], j!(["https://x.example.com/cb"]));
assert_eq!(body["client_uri"], "https://x.example.com");
assert_eq!(
body["grant_types"],
j!(["authorization_code", "refresh_token"])
Expand Down
Loading
Loading