[
https://issues.apache.org/jira/browse/CAMEL-24877?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18153607#comment-18153607
]
Adriano Machado edited comment on CAMEL-24877 at 12/1/26, 5:53 PM:
-------------------------------------------------------------------
*Analysis: not a Camel defect, the server clears setgid for a user outside the
directory's group*
I could not reproduce this as a Camel bug. Findings:
# The trace in the description shows Camel sends {{chmod 2770}} for both
{{/consumer-test/test}} and {{/consumer-test/test/tmp}}
({{{}SftpOperations.buildDirectoryChunks{}}}). The bit is sent for every
directory it creates.
# JSch passes the bit through unchanged: {{SftpATTRS.setPERMISSIONS}} masks
with {{0xFFF}} (octal 07777), which includes setgid.
# I replayed the same sequence with the OpenSSH {{sftp}} client (no Camel)
against a real sshd in a container. The parent {{consumer-test}} was {{2770}}
with group {{{}shared{}}}.
- User in group {{{}shared{}}}: both {{test}} and {{test/tmp}} end as
{{{}2770{}}}.
- User *not* in group {{{}shared{}}}: {{test}} ends as {{770}} and
{{test/tmp}} as {{{}2770{}}}. This is the reported split.
Why: {{test}} is created inside a setgid parent, so it inherits group
{{{}shared{}}}. POSIX {{chmod}} silently clears setgid when the caller is not a
member of the file's group, and the SFTP server still reports success. Since
{{test}} is no longer setgid, {{tmp}} gets the user's primary group, the user
is a member of it, and the chmod keeps the bit.
Suggested fix on the deployment side: add the SFTP user to the group that owns
the directory (or make it the user's primary group). {{id}} for the SFTP user
and {{ls -ld /consumer-test}} would confirm this.
I plan to add a note to the {{chmodDirectory}} documentation saying that the
server may drop setgid when the user is not in the directory's group. Please
say if you would rather close this as "Not A Problem".
_Claude Code on behalf of ammachado_
was (Author: ammachado):
*Analysis: not a Camel defect, the server clears setgid for a user outside the
directory's group*
I could not reproduce this as a Camel bug. Findings:
# 1. The trace in the description shows Camel sends {{chmod 2770}} for both
{{/consumer-test/test}} and {{/consumer-test/test/tmp}}
({{{}SftpOperations.buildDirectoryChunks{}}}). The bit is sent for every
directory it creates.
# JSch passes the bit through unchanged: {{SftpATTRS.setPERMISSIONS}} masks
with {{0xFFF}} (octal 07777), which includes setgid.
# I replayed the same sequence with the OpenSSH {{sftp}} client (no Camel)
against a real sshd in a container. The parent {{consumer-test}} was {{2770}}
with group {{{}shared{}}}.
- User in group {{{}shared{}}}: both {{test}} and {{test/tmp}} end as
{{{}2770{}}}.
- User *not* in group {{{}shared{}}}: {{test}} ends as {{770}} and
{{test/tmp}} as {{{}2770{}}}. This is the reported split.
Why: {{test}} is created inside a setgid parent, so it inherits group
{{{}shared{}}}. POSIX {{chmod}} silently clears setgid when the caller is not a
member of the file's group, and the SFTP server still reports success. Since
{{test}} is no longer setgid, {{tmp}} gets the user's primary group, the user
is a member of it, and the chmod keeps the bit.
Suggested fix on the deployment side: add the SFTP user to the group that owns
the directory (or make it the user's primary group). {{id}} for the SFTP user
and {{ls -ld /consumer-test}} would confirm this.
I plan to add a note to the {{chmodDirectory}} documentation saying that the
server may drop setgid when the user is not in the directory's group. Please
say if you would rather close this as "Not A Problem".
_Claude Code on behalf of ammachado_
> Spring Boot Camel SFTP Consumer: How to apply setgid permissions to all
> directories created by SFTP autoCreate?
> ---------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-24877
> URL: https://issues.apache.org/jira/browse/CAMEL-24877
> Project: Camel
> Issue Type: Improvement
> Components: camel-ftp, camel-sftp
> Reporter: samhithae
> Assignee: Adriano Machado
> Priority: Major
> Fix For: 4.18.3
>
>
>
> We are using Apache Camel SFTP consumer in Spring boot application to poll
> files from a remote directory and create nested directory structures.
> When using _*{{chmodDirectory}}*_ in the camel uri for consumption with
> setgid bit (e.g., {{2770}} or {{{}2775{}}}), Camel only applies the setgid
> bit to the final endpoint directory, but not to intermediate directories
> created during the path build process.
> h2. Expected Behavior:
> All created directories should have the specified permissions, including the
> setgid bit.
> h2. Actual Behavior:
> * Final directory ({{{}/test/tmp{}}}) gets full {{2770}} permissions
> * Intermediate directory ({{{}/test{}}}) gets only {{770}} (setgid bit
> ignored)
> h5. Camel SFTP URI: consumer-test directory is already created, expecting
> sftp consumer to create test/tmp sub-directories
> {code:java}
> "//userId@remoteServer:22/consumer-test/test/tmp?
> password=password&
> streamDownload=false&
> readLock=none&
> delete=false&
> download=false&
> disconnect=false&
> bufferSize=32768&
> stepwise=false&
> maximumReconnectAttempts=2&
> throwExceptionOnConnectFailed=true&
> backoffErrorThreshold=1&
> excludeExt=lock&
> include=.*&
> maxMessagesPerPoll=10&
> chmodDirectory=2770"{code}
> *Logs:*
> {code:java}
> 2026-09-09 05:28:56,107 TRACE
> org.apache.camel.component.file.remote.SftpOperations buildDirectoryChunks -
> Trying to build remote directory by chunk: /consumer-test 2026-09-09
> 05:28:56,361 TRACE org.apache.camel.component.file.remote.SftpOperations
> buildDirectoryChunks - Trying to build remote directory by chunk:
> /consumer-test/test 2026-09-09 05:28:56,616 TRACE
> org.apache.camel.component.file.remote.SftpOperations buildDirectoryChunks -
> Trying to build remote directory by chunk: /consumer-test/test/tmp 2026-09-08
> 05:29:07,361 TRACE org.apache.camel.component.file.remote.SftpOperations
> chmodOfDirectory - Setting permission: 2770 on directory: /consumer-test/test
> 2026-09-08 05:29:07,400 TRACE
> org.apache.camel.component.file.remote.SftpOperations chmodOfDirectory -
> Setting permission: 2770 on directory: /consumer-test/test/tmp {code}
> {{ }}
> Logs show chmod is *attempted* on both directories, but permissions end up
> different.{{{{}}{}}}
> {code:java}
> Actual Permissions
> drwxrwx--- 770 /consumer-test/test ← Missing setgid!
> drwxrws--- 2770 /consumer-test/test/tmp ← Has setgid{code}
> What I've Tried:
> {code:java}
> 1. `chmodDirectory=2770` — setgid only applied to final dir
> 2. `chmodDirectory=2775` — same issue
> 3. `chmodDirectory=775` — works on both dirs (but no setgid)
> 4. `stepwise=true` + `chmodDirectory=2770` — same issue{code}
>
> How to make this Camel sftp consumer to apply setgid permissions to all
> subdirectories instead of just the final directory?
>
> Stackoverflow question:
> [https://stackoverflow.com/questions/80002202/spring-boot-camel-sftp-consumer-how-to-apply-setgid-permissions-to-all-director|http://example.com/]
> Mailing list thread:
> [https://lists.apache.org/thread/hh5hj2kdc4k0lvrof40ykqoxjo4kjkor|http://example.com/]
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)