Skip to content

Commit 4d62c34

Browse files
fix(cdk): Remove fallback mechanism and properly configure user namespaces
Co-Authored-By: Aaron <AJ> Steers <[email protected]>
1 parent cf25939 commit 4d62c34

File tree

4 files changed

+43
-18
lines changed

4 files changed

+43
-18
lines changed

devlog/2025-03-sandboxing-3.md

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ This error occurs because gVisor requires user namespace support for rootless co
1616
The key changes in this implementation:
1717

1818
1. **Update OCI Configuration**:
19-
- Add `umask` setting to the user configuration
20-
- Ensure proper user namespace mapping
19+
- Add proper user namespace configuration to the Linux namespaces section
20+
- Ensure proper user configuration
2121

22-
2. **Modify gVisor Wrapper Script**:
23-
- Add `--network=host` flag to the runsc command
24-
- Maintain the fallback mechanism to direct execution if runsc fails
22+
2. **Remove Fallback Mechanism**:
23+
- Remove the fallback to direct execution to ensure proper sandboxing
24+
- Focus on making gVisor work properly in production environments
2525

2626
3. **Update Dockerfile**:
2727
- Configure kernel parameters to allow unprivileged user namespace cloning
28-
- Maintain existing directory permissions
28+
- Set appropriate permissions for directories
2929

3030
## Technical Approach
3131

@@ -38,8 +38,8 @@ gVisor requires user namespace support for rootless containers. This is a fundam
3838
The solution addresses these issues by:
3939

4040
1. Configuring the OCI bundle with proper user namespace settings
41-
2. Adding network host mode to the runsc command
42-
3. Setting kernel parameters to allow unprivileged user namespace cloning
41+
2. Setting kernel parameters to allow unprivileged user namespace cloning
42+
3. Removing the fallback mechanism to ensure proper sandboxing
4343

4444
## Testing Results
4545

@@ -61,14 +61,30 @@ docker run --rm --privileged airbyte/source-declarative-manifest-gvisor spec
6161
docker run --rm --userns=host airbyte/source-declarative-manifest-gvisor spec
6262
```
6363

64-
While the user namespace error may still occur in some environments due to host-level restrictions, the fallback mechanism ensures the connector still functions by executing the command directly.
64+
The implementation now requires proper user namespace support to function, as the fallback mechanism has been removed to ensure proper sandboxing.
6565

66-
## Considerations for Future Work
66+
## Production Deployment Requirements
6767

68-
1. **Docker Runtime Configuration**: For production use, consider configuring the Docker daemon with user namespace remapping using the `userns-remap` option.
69-
2. **Host-Level Configuration**: Some environments may require additional host-level configuration to enable user namespaces.
70-
3. **Alternative Sandboxing Approaches**: If user namespace support cannot be enabled in the target environment, consider alternative sandboxing approaches like Firejail.
68+
For gVisor to work properly in production environments:
69+
70+
1. **Docker Runtime Configuration**: Configure the Docker daemon with user namespace remapping using the `userns-remap` option in `/etc/docker/daemon.json`:
71+
```json
72+
{
73+
"userns-remap": "default"
74+
}
75+
```
76+
77+
2. **Host-Level Configuration**: Enable user namespaces at the host level:
78+
```bash
79+
echo 'kernel.unprivileged_userns_clone=1' > /etc/sysctl.d/userns.conf
80+
sysctl -w kernel.unprivileged_userns_clone=1
81+
```
82+
83+
3. **Container Runtime Flags**: Run containers with the appropriate flags:
84+
```bash
85+
docker run --security-opt seccomp=unconfined --security-opt apparmor=unconfined --userns=host
86+
```
7187

7288
## Conclusion
7389

74-
This implementation addresses the user namespace issue in the gVisor sandboxing implementation by properly configuring the OCI bundle and adding necessary flags to the runsc command. The fallback mechanism ensures the connector still functions in environments without proper user namespace support.
90+
This implementation addresses the user namespace issue in the gVisor sandboxing implementation by properly configuring the OCI bundle and adding necessary kernel parameters. The removal of the fallback mechanism ensures that the connector will only run with proper sandboxing, which is essential for production use.

docker/sandbox-poc/Dockerfile.gvisor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ USER root
55

66
# Install dependencies
77
RUN apt-get update && \
8-
apt-get install -y curl gnupg apt-transport-https ca-certificates && \
8+
apt-get install -y curl gnupg apt-transport-https ca-certificates procps uidmap && \
99
apt-get clean && \
1010
rm -rf /var/lib/apt/lists/*
1111

docker/sandbox-poc/scripts/gvisor-wrapper.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ shift
66
# Use pre-created OCI bundle directory
77
BUNDLE_DIR="/var/run/oci-bundle"
88

9-
# Run the command with runsc
9+
# Run the command with runsc (no fallback)
1010
cd $BUNDLE_DIR
11-
runsc -TESTONLY-unsafe-nonroot run --bundle=$BUNDLE_DIR container1 || python /airbyte/integration_code/main.py "$COMMAND" "$@"
11+
runsc -TESTONLY-unsafe-nonroot run --bundle=$BUNDLE_DIR container1

docker/sandbox-poc/scripts/oci-config.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,14 @@
1919
"root": {
2020
"path": "rootfs"
2121
},
22-
"linux": {}
22+
"linux": {
23+
"namespaces": [
24+
{"type": "mount"},
25+
{"type": "network"},
26+
{"type": "uts"},
27+
{"type": "pid"},
28+
{"type": "ipc"},
29+
{"type": "user"}
30+
]
31+
}
2332
}

0 commit comments

Comments
 (0)