Kerberos.NET icon indicating copy to clipboard operation
Kerberos.NET copied to clipboard

[security] Incorrect file permissions for ccache file

Open dafanasiev opened this issue 2 years ago • 3 comments

Describe the bug Only owner can read/write ccache file (when krb5 tiket cache store as local file). Currently (at least on Linux) the generated ccache file has the wrong permissions (because of umask?).

To Reproduce

var client = new KerberosClient(new Krb5Config
{
    Defaults =
    {
        DnsLookupKdc = false,
        DefaultCCacheName = "FILE:/tmp/ccache.test",   // file not exists
    },
})
{
    CacheInMemory = false
};

var kerbCred = new KerberosPasswordCredential("[email protected]", "password", "company.corp");

client.PinKdc("company.corp", "dc.company.corp");
await client.Authenticate(kerbCred);

// see in shell: 
//
// # umask
// 0002
// # ls -la /tmp/ccache.test
// -rw-rw-r--  ......  /tmp/ccache.test

Additional context The same problem was previously fixed in nuget cli: https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Packaging/NuGetExtractionFileIO.cs

dafanasiev avatar Sep 09 '23 07:09 dafanasiev

Why would we want to allow more than the owner to access the ticket cache for their own user?

SteveSyfuhs avatar Sep 09 '23 18:09 SteveSyfuhs

Why would we want to allow more than the owner to access the ticket cache for their own user?

No, we don't want that. Now (with umask=0002) any user can read (and any user in owner group can read-write) saved ticket. We need to set the unix file security attributes explicitly, regardless of the umask value.

See also: https://github.com/krb5/krb5/blob/master/src/lib/krb5/ccache/cc_file.c#L866-L873

dafanasiev avatar Sep 11 '23 05:09 dafanasiev