Files
fips/packaging/windows
Johnathan Corgan 7ac3bc51ea Restrict C:\ProgramData\fips to SYSTEM and Administrators
install-service.ps1 created C:\ProgramData\fips without setting an ACL,
so it inherited C:\ProgramData's access: any local user could read the
node's identity key there, and could create a fips.yaml, fips.key,
hosts, peers.allow or peers.deny in the directory before one existed,
for the service, running as LocalSystem, to read. The service log is
written there too.

The installer now builds an ACL that grants only SYSTEM and
Administrators and does not inherit, and creates a new directory with
that ACL already applied, using the .NET call each PowerShell edition
provides. Created first and restricted afterwards, the empty directory
would carry C:\ProgramData's access in between, and any local user
could turn it into a junction in that time with no privilege and
without changing its owner.

An existing directory is refused if it is a link or junction or is
owned by an account other than SYSTEM, Administrators or the installing
administrator, since a user who created it could swap it for a link to
another directory. Otherwise the installer makes Administrators the
owner, refuses the directory if it has since become a link and any link
or folder inside it, applies the ACL, and resets the owner and ACL of
each existing file. That check runs before the ACL is applied, because
applying it rewrites the inherited entries of everything below the
directory, and runs again after it and after the reset. Every icacls
call acts on a link rather than its target and has its exit code
checked. Files created in the directory later, by the service or
fipsctl keygen, take the same ACL. Well-known SIDs are used so the step
works on non-English Windows.

A user who created the directory keeps full control of it through the
entry C:\ProgramData's CREATOR OWNER grant leaves for their account,
and taking ownership changes only the owner. So each refusal tells the
operator to copy out anything needed and delete the directory, taking
ownership only if that is what it takes to delete it, and an icacls
failure says to delete the directory or the file, or simply retry if
the file has gone.

Packaging tests check the order of these steps and that they come
before any path inside the directory is touched; that the ACL is built
with both SIDs and both inheritance flags and passed to the directory's
creation; the refusal conditions themselves (the owner test, the
directory link test at the start and in each recheck, and a link or
folder entry each refused on its own); that every icacls call acts on
links and is checked; and that takeown is never offered as the
recovery. The README and the fips reference say that reading the
directory now needs an elevated prompt (an unelevated foreground run
may skip the config there or fail with an access error), that the
installer should run before fipsctl keygen, and that it should run
again after files are moved into the directory, since a moved file
keeps its old permissions.
2026-09-24 23:39:56 +00:00
..