Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1543 emptry crl file fails http tpc pull transfer #1547

Merged

Conversation

ccaffy
Copy link
Contributor

@ccaffy ccaffy commented Nov 2, 2021

Fixes #1543

@bbockelm
Copy link
Contributor

bbockelm commented Nov 2, 2021

Does this actually fix #1543 though? In the last comment there, you mention it fails if the CRL file is non-empty and contains no valid CRLs. Shouldn't we use some of the internal XRootD routines to parse the file and see if there's one CRLs present?

@abh3
Copy link
Member

abh3 commented Nov 2, 2021 via email

@bbockelm
Copy link
Contributor

bbockelm commented Nov 2, 2021

However, we should also make sure that malicious injection of an empty/invalid CRL file does not completely eliminate CRL checking for all time

This is a file periodically generated by XRootD in the admin directory. I figure if the attacker owns the admin directory, then it's already game over.

It's also an aggregate of all CRLs available - if the attacker controls all your CRLs, then it's probably also game over.

@abh3
Copy link
Member

abh3 commented Nov 2, 2021 via email

@bbockelm
Copy link
Contributor

bbockelm commented Nov 2, 2021

Indeed, that's a fantastic idea! I expect this to be a pretty rare occurrence so a warning message seems warranted.

@ccaffy - does this sound good to you?

@ccaffy
Copy link
Contributor Author

ccaffy commented Nov 3, 2021

Hi all, thanks for your comments!

To sum things up, you would like to disable the CRL checking and display a warning message if there is at least one wrong CRL encountered during the CRL processing?

That's sounds a good plan to me :)

@ccaffy
Copy link
Contributor Author

ccaffy commented Nov 3, 2021

Does this actually fix #1543 though? In the last comment there, you mention it fails if the CRL file is non-empty and contains no valid CRLs. Shouldn't we use some of the internal XRootD routines to parse the file and see if there's one CRLs present?

I thought that checking that the aggregated-CRL file is not empty would be sufficient as curl already checks the validity of its content. In my opinion, failing a transfer due to an empty CRL file is not acceptable, but failing a transfer due to a wrong content is acceptable.
Hence why I only added a check on the emptiness of the file ;)

@bbockelm
Copy link
Contributor

bbockelm commented Nov 3, 2021

To sum things up, you would like to disable the CRL checking and display a warning message if there is at least one wrong CRL encountered during the CRL processing?

Not quite -- I'm thinking that if there are no CRLs in the CRL file then we disable CRL checking. Here, I'm willing to define "valid" as simply parseable as a CRL (not looking closely at the contents). Particularly, we should have a routine like this one; instead of looping through all CRLs in a file, return successful as soon as a single one is present.

Actually, that suggests a simpler approach. Since we are writing the CRLs to this file in the first place, why not keep track of the number written and, if there were zero, simply don't invoke the corresponding curl option?

@ccaffy
Copy link
Contributor Author

ccaffy commented Nov 3, 2021

Actually, that suggests a simpler approach. Since we are writing the CRLs to this file in the first place, why not keep track of the number written and, if there were zero, simply don't invoke the corresponding curl option?

Yes, for me this is fine :) I can implement that 👍

@ccaffy
Copy link
Contributor Author

ccaffy commented Nov 10, 2021

I updated the code yesterday :) Please tell me if this is OK for you so that this fix can be merged :)

@xrootd-dev
Copy link

xrootd-dev commented Nov 10, 2021 via email

Copy link
Member

@abh3 abh3 left a comment

Choose a reason for hiding this comment

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

A couple of questions and perhaps needed changes before we merge this. Sorry for taking so long.

.gitignore Outdated
@@ -58,3 +58,5 @@ xrootd.spec
dist
*.egg-info
bindings/python/VERSION
cmake-*
.idea/
Copy link
Member

Choose a reason for hiding this comment

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

Why are these being added? Is it a problem in your own repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Andy,

No problem :)

Because I use CLion as IDE with local code deployed on a VM. The cmake-* directories is the equivalent of the build directory.
The .idea directory is created by CLion.
I just do not want these directories to be pushed to the project :)

Now that you said this, it looks like I can put these excludes in my local .git/info/exclude file. I will therefore remove these two lines from the .gitignore file

@@ -198,11 +209,17 @@ CRLSet::processFile(file_smart_ptr &fp, const std::string &fname)
return false;
}
}
if(!m_atLeastOneValidCRLFound)
m_atLeastOneValidCRLFound = atLeastOneValidCRLFound;
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this mean that once a valid CRL is found a subsequent scan that doesn't find one will not be registered as such? Won't that be a problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I only modify the variable m_atLeastOneValidCRLFound if this variable is false. So, once a valid CRL is found, the m_atLeastOneValidCRLFound will be set to true and therefore will never be assigned anymore during the XrdTlsTempCA::Maintenance() loop.

That way, we only enable CRL checking if there is at least one valid CRL found during the Maintenance run :)

Copy link
Member

Choose a reason for hiding this comment

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

What about this little issue that doesn't seem quite right.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but you should consider that the next time the maintenance loop runs there may be no valid CRLs. I know that's unlikely but unlikely things happen. I think you should always update the current state of the maintenance loop otherwise that look does half the j0ob.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If during the next time the maintenance loop runs there is no valid CRL file, do we agree that the CRL checking must be disabled?

Copy link
Member

Choose a reason for hiding this comment

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

I think that if the current CRL file is replaced with a bad CRL file then, yes. It should be disabled. This is dynamic because the maintenance check tries to create a CRL file and if it fails then a) if the previous CRL file is still enforce then we need do nothing, or b) it gets replaced with a null file then we need top disable CRL checking. So, in the end it depends on the state the maintenance run leaves the CRL file (something I have not researched).

@abh3
Copy link
Member

abh3 commented Dec 1, 2021 via email

@ccaffy
Copy link
Contributor Author

ccaffy commented Dec 1, 2021

I thought we wanted the composite CRL file to reflect what is in the /etc/grid-security/certificates directory and not trying to see if in the previous run, a CRL that was found is not found anymore or is replaced by a null file in the next run.

Here are the tests I did:

First, best case scenario, there are two valid pem files in the /etc/grid-security/certificates directory:

//Server side
211201 13:42:09 23886 TPC_TempCA: Reloading the list of CAs and CRLs in directory

Composite CRL file:

-----BEGIN X509 CRL-----
[...] CRL1 file content
-----END X509 CRL-----
-----BEGIN X509 CRL-----
[...] CRL2 file content
-----END X509 CRL-----

Now, I empty the CRL2 file content:

root@xrootd-ccaffy-dev01 xrootd-run]# cat /etc/grid-security/certificates/my_crl_file_2.crl
[root@xrootd-ccaffy-dev01 xrootd-run]#

... and after the next run of the Maintenance:

-----BEGIN X509 CRL-----
[...] CRL1 file content
-----END X509 CRL-----

The composite CRL file is re-generated. Containing only the first CRL file as I emptied the second CRL file.

Now I will modify the CRL1 file content to break the CRL correctness of this file:

[root@xrootd-ccaffy-dev01 xrootd-run]# truncate -s 500 /etc/grid-security/certificates/my_crl_file.crl

Then the composite CRL file is re-generated and contains nothing:

[xrootddev@xrootd-ccaffy-dev01 xrootd-run]$ cat /var/spool/xrootd/.xrdtls/crl_file.pem
[xrootddev@xrootd-ccaffy-dev01 xrootd-run]$

A TPC transfer will then have the CRL check disabled:

211201 13:56:48 23872 TPC_TpcHandler: No valid CRL file has been found in the file /var/spool/xrootd/.xrdtls/crl_file.pem. Disabling CRL checking.

Is this the behaviour we expect? Because for me, the composite CRL file should be an image of what is in the /etc/grid-security/certificates directory.

To sum things up, the composite CRL file is completely re-generated at each Maintenance run :)

Sorry for the time spent on this topic, but I really need to understand and I want to be sure that you have the full picture of why I did this implementation like this ;)

@xrootd-dev
Copy link

xrootd-dev commented Dec 2, 2021 via email

@ccaffy
Copy link
Contributor Author

ccaffy commented Dec 2, 2021

Alright then, I get rid of the if statement. Thanks for your comments :)

…of the logic so that if at least one valid CRL file is found, the CRL checking is activated
@abh3 abh3 merged commit a384ecb into xrootd:master Dec 3, 2021
@ccaffy ccaffy deleted the 1543-emptry-crl-file-fails-http-tpc-pull-transfer branch March 15, 2022 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[XrootdHttpTPC] Empty CRL file fails a HTTP TPC pull transfer
4 participants