158 / 163 · C11 · 8 min
Authentication
An operating system must reliably identify the principal behind every process before it can enforce security policy. This chapter examines how identities are attached to processes through inheritance and through the initial binding that occurs at login.
In this lesson
Principals, Agents and Security Decisions
Every service an operating system performs is requested by a process that acts as an agent for some principal. The principal may be a human user, a group of users or even a particular program. The OS consults the identity stored in the process-control block and then decides whether the agent may touch a given object. Without a trustworthy identity, principles such as least privilege cannot be applied.
How Identities Are Inherited
A new process is almost always created by an existing process via a call such as fork. The operating system simply copies the identity field from the parent's process-control block into the child's. Consequently every process that belongs to the same login session shares the same authenticated identity unless an explicit change is later made.
Initial Identity Binding at Login
When a user first approaches the machine the operating system must verify the claimed identity. After a successful check the OS itself creates the very first process (typically a shell or window manager) and writes the proper user identifier into that process's control block. All later activity of the user rests on this one-time authentication decision.
Credentials Remember Earlier Decisions
Once an identity has been bound, the operating system can issue credentials that record an earlier “access-allowed” decision so that the check need not be repeated. Those credentials live in per-process structures such as page tables or the open-file table.
Pitfalls
- Writing user A's identity into user B's process produces a complete privilege mix-up.
- After the initial authentication most systems never re-check the identity for the lifetime of the process, so an early mistake is almost impossible to correct.
Run an example
Minimum C11 · complete program · Download .c
#include <stdio.h>
#include <stdint.h>
typedef struct {
uint32_t uid;
const char *username;
} Identity;
void attach_identity(Identity *id, uint32_t uid, const char *name) {
id->uid = uid;
id->username = name;
}
int main(void) {
Identity login_id;
printf("=== OS Authentication Simulation ===\n");
printf("User attempts login...\n");
/* Simulated successful authentication */
attach_identity(&login_id, 1000, "alice");
printf("Authenticated: UID=%u, User=%s\n", login_id.uid, login_id.username);
printf("Creating initial process (shell) with attached identity.\n");
printf("Forking child process for command execution.\n");
printf("Child inherits UID=%u from parent.\n", login_id.uid);
printf("Security policy can now be applied based on this identity.\n");
return 0;
}
Compile locally
gcc -std=c11 -Wall -Wextra -Wpedantic -Werror ostep-54-authentication.c -o example && ./exampleExpected result
=== OS Authentication Simulation ===
User attempts login...
Authenticated: UID=1000, User=alice
Creating initial process (shell) with attached identity.
Forking child process for command execution.
Child inherits UID=1000 from parent.
Security policy can now be applied based on this identity.
CHECK YOUR UNDERSTANDING
Close the answer. Explain it.
How does a newly created process normally obtain its security identity, and how does the login process differ?
Show a reference answer
An ordinary process inherits the identity of the parent that created it; the OS copies the field while building the child's process-control block. The login process has no parent to inherit from, so the OS writes the identity itself after it has verified the user's credentials.
Check the sources
Drafts and official chapters change. The version mark is only the example’s minimum.