Skip to content

Commit e82e2bf

Browse files
authored
Bind trow to IPv6 and IPv4 by default (#436)
* chart: better securitycontext * UID and GID in the 0-10_000 range * readonly filesystem * disable privilege escalation * rename fn * improve CLI args * bind "::" which maps to both ipv4 and ipv6 * add emptydir /data for webhooks
1 parent 8e25b6f commit e82e2bf

File tree

8 files changed

+36
-34
lines changed

8 files changed

+36
-34
lines changed

charts/trow/templates/statefulset.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ spec:
2828
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
2929
imagePullPolicy: {{ .Values.image.pullPolicy }}
3030
args:
31-
- "-n"
31+
- "--hostname"
3232
- {{ .Values.trow.domain | quote }}
3333
{{- if and (.Values.trow.user) (.Values.trow.password) }}
3434
- "--user"

charts/trow/templates/webhooks/deployment.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ spec:
4848
imagePullPolicy: {{ .Values.image.pullPolicy }}
4949
args:
5050
- "--tls=/etc/trow/webhook-cert/cert,/etc/trow/webhook-cert/key"
51-
- "-n"
51+
- "--hostname"
5252
- {{ .Values.trow.domain | quote }}
5353
{{- if include "trow.hasConfigFile" . }}
5454
- "--config-file=/etc/trow/config.yaml"
@@ -58,7 +58,7 @@ spec:
5858
value: {{ .Values.trow.logLevel }}
5959
ports:
6060
- name: webhook
61-
containerPort: 8443
61+
containerPort: 8000
6262
{{- with .Values.containerSecurityContext }}
6363
securityContext:
6464
{{- toYaml . | nindent 10 }}
@@ -67,6 +67,8 @@ spec:
6767
- name: webhook-cert-translated
6868
mountPath: /etc/trow/webhook-cert
6969
readOnly: true
70+
- name: data-emptydir
71+
mountPath: /data
7072
{{- if include "trow.hasConfigFile" . }}
7173
- name: trow-cfg
7274
mountPath: /etc/trow/config.yaml
@@ -89,6 +91,8 @@ spec:
8991
{{- end }}
9092
- name: webhook-cert-translated
9193
emptyDir: {}
94+
- name: data-emptydir
95+
emptyDir: {}
9296
{{- if include "trow.hasConfigFile" . }}
9397
- name: trow-cfg
9498
secret:

charts/trow/values.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ image:
88
repository: ghcr.io/trow-registry/trow
99
tag:
1010
pullPolicy: IfNotPresent
11-
12-
## Applies to the Trow Statefulset and the webhooks Deployment
1311
podSecurityContext:
14-
runAsUser: 333333
15-
runAsGroup: 333333
16-
fsGroup: 333333
17-
18-
containerSecurityContext: {}
12+
runAsNonRoot: true
13+
runAsUser: 1000
14+
runAsGroup: 3000
15+
fsGroup: 3000
16+
containerSecurityContext:
17+
readOnlyRootFilesystem: true
18+
allowPrivilegeEscalation: false
1919

2020
trow:
2121
## if using NodePort, this can be set to 127.0.0.1:XXXX

src/main.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::fs::File;
22
use std::io::prelude::*;
3-
use std::net::{IpAddr, SocketAddr};
3+
use std::net::{IpAddr, SocketAddr, TcpListener, ToSocketAddrs};
44
use std::path::{Path, PathBuf};
55
use std::str::FromStr;
66

@@ -15,18 +15,9 @@ use trow::{TlsConfig, TrowConfig};
1515
#[command(about = "The Cluster Registry")]
1616
#[command(author, version, long_about = None)]
1717
struct Args {
18-
/// Name of the host or interface to start Trow on
19-
#[arg(long, default_value = "0.0.0.0")]
20-
host: IpAddr,
21-
22-
/// Port that trow will listen on
23-
#[arg(
24-
short,
25-
long,
26-
default_value_if("tls", ArgPredicate::IsPresent, "8443"),
27-
default_value("8000")
28-
)]
29-
port: u16,
18+
/// Interface to bind Trow on
19+
#[arg(long, default_value = "[::]:8000")]
20+
bind: SocketAddr,
3021

3122
/// Path to TLS certificate and key, separated by ','
3223
#[arg(
@@ -44,10 +35,10 @@ struct Args {
4435

4536
/// Host name for registry.
4637
///
47-
/// Used in AdmissionMutation webhook.
38+
/// Used in AdmissionMutation webhook and token issuer.
4839
/// Defaults to `host`.
49-
#[arg(short, long)]
50-
name: Option<String>,
40+
#[arg(short = 'n', long)]
41+
hostname: Option<String>,
5142

5243
/// Don't actually run Trow, just validate arguments.
5344
///
@@ -81,8 +72,13 @@ async fn main() {
8172
tracing_subscriber::fmt::init();
8273

8374
let args = Args::parse();
84-
let addr = SocketAddr::new(args.host, args.port);
85-
let host_name = args.name.unwrap_or(addr.to_string());
75+
let addr = args
76+
.bind
77+
.to_socket_addrs()
78+
.expect("Could not resolve bind address")
79+
.next()
80+
.expect("Bound address did not resolve to anything");
81+
let host_name = args.hostname.unwrap_or(addr.to_string());
8682

8783
let mut builder = TrowConfig::new();
8884
builder.data_dir = PathBuf::from_str(args.data_dir.as_str()).expect("Invalid data path");

src/routes/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ async fn login(
176176
auth_user: ValidBasicToken,
177177
State(state): State<Arc<TrowServerState>>,
178178
) -> Result<TrowToken, Error> {
179-
let tok = trow_token::new(auth_user, &state.config);
179+
let tok = trow_token::create_token(auth_user, &state.config);
180180
match tok {
181181
Ok(t) => Ok(t),
182182
Err(e) => {

src/routes/response/trow_token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ struct TokenClaim {
137137
* Create new jsonwebtoken.
138138
* Token consists of a string with 3 comma separated fields header, payload, signature
139139
*/
140-
pub fn new(
140+
pub fn create_token(
141141
vbt: ValidBasicToken,
142142
config: &TrowConfig,
143143
) -> Result<TrowToken, jsonwebtoken::errors::Error> {

tests/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ mod cli {
4646
#[test]
4747
fn host_name_parsing() {
4848
get_command()
49-
.args(["-n", "myhost.com"])
49+
.args(["--hostname", "myhost.com"])
5050
.assert()
5151
.success()
5252
.stdout(predicate::str::contains(": \"myhost.com\""));
5353

5454
get_command()
55-
.args(["--name", "trow.test"])
55+
.args(["--hostname", "trow.test"])
5656
.assert()
5757
.success()
5858
.stdout(predicate::str::contains(": \"trow.test\""));

tests/smoke_test.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ mod smoke_test {
3333
drop(listener);
3434

3535
let mut child = Command::new("./target/debug/trow")
36-
.arg(format!("--host={}", if ipv6 { "::" } else { "0.0.0.0" }))
37-
.arg(format!("--port={port}"))
36+
.arg(format!(
37+
"--bind={}",
38+
format!("{}:{port}", if ipv6 { "[::]" } else { "0.0.0.0" })
39+
))
3840
.arg(format!("--data-dir={}", temp_dir.display()))
3941
.env_clear()
4042
.envs(Environment::inherit().compile())

0 commit comments

Comments
 (0)