Skip to content
Open
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
20 changes: 4 additions & 16 deletions services/file-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,18 @@ COPY --from=builder /app/target/release/file-service /app/file-service
RUN useradd -r -u 1001 appuser
USER appuser

# demo-coggtm tenant variant -- NEVER merge this to `main`. The tenant runs the
# image this branch builds (tag `tenant-coggtm`), so baking the switch in here is
# the only way to make its uploads fail permanently: it survives pod restarts,
# Redis restarts, TTL expiry and idle-suspend/wake, and needs no chart override:
# the deploy runner renders charts from its own bundled tree, whose file-service
# values are `config: {}` and whose build_helm_args sets a fixed list of
# config.* keys that does not include this one, so nothing overrides the image.
# Anything that does set the variable explicitly still wins -- docker-compose.yml
# passes false, so local stacks behave like the golden app.
ENV FILE_UPLOAD_ALWAYS_FAIL=true

# Click-triggered notification failure (same bake rationale as above): sharing
# a file publishes the file_shared event to a nonexistent SNS topic, so every
# share click fails with a real AWS SNS error and fires the
# Click-triggered notification failure: sharing a file publishes the
# file_shared event to a nonexistent SNS topic, so every share click fails
# with a real AWS SNS error and fires the
# NotificationEventPublishFailure alert at admin-service (incident + Devin
# session + Slack, attributed to the sharing user via reporter_email). The
# share record is still saved, but the request returns the AWS error so the
# UI shows a red failure banner. docker-compose.yml passes false, so local
# stacks behave like the golden app.
ENV FILE_SHARE_EVENT_ALWAYS_FAIL=true

# With uploads failing permanently (above), users would have no files to share.
# Seeding gives every user a few demo documents on their first file listing,
# so the share-notification failure is demoable alongside the upload failure.
# so the share flow is demoable on an account that has uploaded nothing yet.
# docker-compose.yml passes false, so local stacks behave like the golden app.
ENV FILE_SEED_DEMO_DOCS=true
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.

Expand Down
47 changes: 47 additions & 0 deletions services/file-service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,33 @@ impl SnsConfig {
mod tests {
use super::{parse_bool, parse_bool_env};

fn image_enables_upload_failure(dockerfile: &str) -> bool {
let logical_lines = dockerfile.replace("\\\r\n", " ").replace("\\\n", " ");

logical_lines.lines().any(|line| {
let mut instruction = line.split_ascii_whitespace();
if !instruction
.next()
.is_some_and(|word| word.eq_ignore_ascii_case("ENV"))
{
return false;
}

let fields: Vec<_> = instruction.collect();
fields.iter().enumerate().any(|(index, field)| {
if let Some((name, value)) = field.split_once('=') {
return name == "FILE_UPLOAD_ALWAYS_FAIL"
&& parse_bool(value.trim_matches(['"', '\'']), false);
}

*field == "FILE_UPLOAD_ALWAYS_FAIL"
&& fields
.get(index + 1)
.is_some_and(|value| parse_bool(value.trim_matches(['"', '\'']), false))
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
})
})
}

#[test]
fn parse_bool_accepts_true_and_one() {
for raw in ["true", "TRUE", " True ", "1"] {
Expand Down Expand Up @@ -155,4 +182,24 @@ mod tests {
}
assert!(!super::ServerConfig::from_env().upload_always_fail);
}

#[test]
fn production_image_does_not_enable_upload_failures() {
assert!(!image_enables_upload_failure(include_str!("../Dockerfile")));
}

#[test]
fn detects_upload_failure_image_defaults() {
for dockerfile in [
"ENV FILE_UPLOAD_ALWAYS_FAIL=true",
"env FILE_UPLOAD_ALWAYS_FAIL 1",
"ENV OTHER=value FILE_UPLOAD_ALWAYS_FAIL=\"TRUE\"",
"ENV OTHER=value \\\n FILE_UPLOAD_ALWAYS_FAIL='1'",
] {
assert!(
image_enables_upload_failure(dockerfile),
"dockerfile={dockerfile}"
);
}
}
}
Loading