0

my question is about using mTLS for API access control and authentication.

I understand in mTLS, both the server and client (making the API request) will verify each other's identity. This allows the server to verify if the client certificate is valid and issued by a trusted CA. However, this alone does not let the server identify whether this client should be allowed to access the API...

To get further assurance that the client is who they claim to be, does it make sense to implement something like certificate pinning on the server side? Else, what would be the best practice for API access control and authentication?

    1 Answer 1

    2

    Client certificate authentication should give you strong assurance that the client is whom they claim to be (as specified in the certificate subject or through the Subject Alternative Name extension). Otherwise, this would indicate a major problem with the public-key infrastructure or the way clients protect their private keys.

    Of course it can be useful to consider defense-in-depth mechanisms like public-key pinning. However, the question is what you're trying to achieve, and there are some implementations challenges. As to the first aspect, server-side key pinning can prevent the server from accepting certificates that have been falsely issued by a compromised or rogue CA. This makes a lot of sense in a large infrastructure with many different CAs, but in your case, you should only deal with one CA: your own. If you want protection against the case that your CA is compromised, then pinning is valid, otherwise you may not achieve anything useful. As to the implementation, I'm not aware of any standard or common webserver software which allows the server to pin public keys of the client. The opposite is of course well-known from the (now largely obsolete) HTTP Public Key Pinning extension. So you may have to implement this mechanism yourself.

    To strengthen certificate-based authentication, you should make sure the CA keys are very well protected, ideally through a hardware security module or at least a completely separate, physically isolated machine.

    Access control in the sense of authorization is an entirely different topic. Client certificates only deal with authentication.

    4
    • Thanks for clarifying about server-side key pinning @Ja1024, seems like mTLS doesn't support/involve this feature... To give a bit more context, I posted my question from the perspective of wanting to be able to tell if the client is someone that I am expecting - from your answer, I should be able to create a whitelist based on the client's subject / SAN right?
      – huthut28
      CommentedJun 20, 2024 at 10:25
    • Yes, but I’m not sure what kind of attack this is supposed to prevent. If the client ID from the certificate doesn’t exist in the application database, then the application should already handle this case by immediately rejecting the request. You won’t gain much by introducing a whitelist of known user IDs at TLS level. An attacker who has managed to compromise the CA will be more interested in getting certificates for valid users, and this cannot be detected with a whitelist.
      – Ja1024
      CommentedJun 20, 2024 at 11:45
    • I see, so the client ID check should be implemented before the TLS phase. The idea is to prevent the scenario whereby just anyone with a valid certificate can call the API; to limit the API for use only by valid users with a valid certificate (that may be from a CA that I don't control).
      – huthut28
      CommentedJun 24, 2024 at 2:34
    • You haven’t said which server software you’re using, but both in nginx and Apache, you explicitly specify the CA which is allowed to issue client certificates. So there is no “CA I don’t control”. The only CA that will be accepted is your own (or the one you’ve specified). It’s not possible for a random CA to issue client certificates for your API, because this would obviously defeat the purpose of mTLS.
      – Ja1024
      CommentedJun 24, 2024 at 2:59

    You must log in to answer this question.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.