Skip to content

Conversation

@dynamic-entropy
Copy link
Collaborator

@dynamic-entropy dynamic-entropy commented Aug 6, 2025

Fix #2550

In 8ce935f, the desired goal is to add the CGI parameter authz to the "Destination" of the MOVE operation before it is evaluated for access permissions.

After a redirection. the authorization header takes the form of a CGI parameter and is no longer present in the redirected request.

Optionally, one can instruct curl to send the authorization header on redirect with --location-trusted; however, this is not the default behaviour.
Note that the way things are implemented currently, the use of --location-trusted will not work either after redirection, (as tested here #2550 (comment) since the presence of authz in the resource url will prevent its copying into the header2cgi string.

auto it = std::find_if(prot->hdr2cgimap.begin(), prot->hdr2cgimap.end(),[key](const auto & item) {
return !strcasecmp(key,item.first.c_str());
});
if (it != prot->hdr2cgimap.end() && (opaque ? (0 == opaque->Get(it->second.c_str())) : true)) {
std::string s;
s.assign(val, line+len-val);
trim(s);
addCgi(it->second,s);

@dynamic-entropy dynamic-entropy force-pushed the rename-after-redirection branch 4 times, most recently from c09ee62 to 27f4cb5 Compare August 11, 2025 10:41
Copy link
Collaborator Author

@dynamic-entropy dynamic-entropy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really mean "anything" here or do we only need authz cgi parameter.

// We assume that anything appended to the CGI str should also
// apply to the destination in case of a MOVE.
if (strchr(destination.c_str(), '?')) destination.append("&");
else destination.append("?");
destination.append(hdr2cgistrEncoded.c_str());

Copy link
Collaborator Author

@dynamic-entropy dynamic-entropy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bbockelm made the requested changes for parsing.

Will defer to @amadio and @ccaffy for comments on options for handling multiple redirects through a manager node.

Copy link
Contributor

@ccaffy ccaffy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it actually OK that this goes to XrdHttpUtils so that unit tests are created with different cases? Including tests like authauthauthz= for example

@dynamic-entropy dynamic-entropy force-pushed the rename-after-redirection branch 2 times, most recently from 68db077 to 7a98d1d Compare August 14, 2025 11:02
@dynamic-entropy dynamic-entropy requested a review from ccaffy August 14, 2025 11:05
@dynamic-entropy dynamic-entropy force-pushed the rename-after-redirection branch from 7a98d1d to 602c395 Compare August 14, 2025 12:55
@dynamic-entropy dynamic-entropy requested a review from ccaffy August 14, 2025 12:58
Copy link
Contributor

@ccaffy ccaffy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good, think about squashing your commits please before merging :)

@dynamic-entropy dynamic-entropy force-pushed the rename-after-redirection branch from 602c395 to 74db9e9 Compare August 14, 2025 13:03
@dynamic-entropy dynamic-entropy requested a review from amadio August 14, 2025 13:03
@dynamic-entropy
Copy link
Collaborator Author

Thankyou!

I have squashed the unit test and related changes in a single commit. The rest of the commits include conceptually separate changes, and I would like to keep them as is.

@dynamic-entropy dynamic-entropy force-pushed the rename-after-redirection branch from 74db9e9 to a91e055 Compare August 14, 2025 13:09
@dynamic-entropy
Copy link
Collaborator Author

Also rebased on master.

@ccaffy
Copy link
Contributor

ccaffy commented Aug 14, 2025

I think we can discuss with @ccaffy about the more thorough fix for the host check issue outlined in one of my comments -- but that seems clearly out of scope for this one.

Yes, feel free to open a new issue if that is not been done already ;)

@dynamic-entropy
Copy link
Collaborator Author

Reworded commits and opened the issue from Brian's comments: #2572

@amadio
Copy link
Member

amadio commented Aug 21, 2025

I discussed this with @abh3 yesterday. The conclusion is that the simplest fix should be applied here, i.e., just move the lines added by commit 6e01c0d to where moves are processed (shown below):

case XrdHttpReq::rtMOVE:
{
// --------- MOVE
memset(&xrdreq, 0, sizeof (ClientRequest));
xrdreq.mv.requestid = htons(kXR_mv);
std::string s = resourceplusopaque.c_str();
s += " ";
char buf[256];
char *ppath;
int port = 0;
if (parseURL((char *) destination.c_str(), buf, port, &ppath)) {
prot->SendSimpleResp(501, NULL, NULL, (char *) "Cannot parse destination url.", 0, false);
return -1;
}
char buf2[256];
strcpy(buf2, host.c_str());
char *pos = strchr(buf2, ':');
if (pos) *pos = '\0';
// If we are a redirector we enforce that the host field is equal to
// whatever was written in the destination url
//
// If we are a data server instead we cannot enforce anything, we will
// just ignore the host part of the destination
if ((prot->myRole == kXR_isManager) && strcmp(buf, buf2)) {
prot->SendSimpleResp(501, NULL, NULL, (char *) "Only in-place renaming is supported for MOVE.", 0, false);
return -1;
}

Since we plan to support access_token as a synonym of authz in the future, the extra opaque from the source should be appended verbatim to the destination, as it's currently done, otherwise it will not work for access_token later.

@dynamic-entropy dynamic-entropy force-pushed the rename-after-redirection branch from c6c2ed3 to bd575c1 Compare August 22, 2025 09:04
@dynamic-entropy dynamic-entropy requested a review from amadio August 22, 2025 09:07
@dynamic-entropy dynamic-entropy force-pushed the rename-after-redirection branch from bd575c1 to 58821f6 Compare August 25, 2025 17:37
@dynamic-entropy dynamic-entropy requested a review from amadio August 25, 2025 17:40
@dynamic-entropy dynamic-entropy force-pushed the rename-after-redirection branch from 58821f6 to b5ca86f Compare August 26, 2025 14:12
@dynamic-entropy dynamic-entropy force-pushed the rename-after-redirection branch from b5ca86f to 3f71357 Compare September 9, 2025 12:53
@amadio
Copy link
Member

amadio commented Sep 9, 2025

I think we agreed to have the tests added in a separate pull request (i.e. #2575), so could you please leave here just the two commits with fixes? Thank you.

@dynamic-entropy
Copy link
Collaborator Author

We did revise that and agreed that it is good for the tests to go in with this PR and if we ever revist them they can buid / modify them.
The reason being that these tests already take care of cleanup as required for subsequent runs.

On a different note: Actually I find this better than the XRootD tests as they leave no files but only last X=20 lines for one to debug after.

Move operations from a manager should succed
after redirection
- Add tests for rename operation with HTTP
  - MOVE operation is currently fails
	after redirection
  - Thus the tests assert against http code 401;
    a fix would change it to 201 instead
  - For redirection from meta-manager; move failes
	for a manager node
…peration; this allows rename after redirections
@amadio amadio force-pushed the rename-after-redirection branch from 9d5ff87 to dde60fb Compare September 9, 2025 16:14
@amadio amadio added this to the 5.9.0 milestone Sep 9, 2025
@amadio amadio merged commit f1de203 into xrootd:master Sep 9, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

File rename over davs/https fails when using token authentication and redirection.

4 participants