Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Fewer rights and a smaller bill

After this lesson: I can give a service only the rights it needs and keep cost down.

50 min lessonNo commands

A weekend bill of £9,000

A developer at a small firm pastes a cloud access key into a public code page by mistake. The key has every right in the account.

By Saturday a stranger has found it and started fifty large servers. On Monday the bill is £9,000. Two habits would have stopped this: fewer rights, and an alert on spending.

By the end of this lesson

Note

I can give a service only the rights it needs and keep cost down.

Key words

WordWhat it meansExample
Identitywho or what is making a request
Permissionone thing an identity may doread:orders
Policya list of permissions
Rolean identity a service uses, with its own policy
Least privilegeonly the rights the job needs
Budget alerta message when spending passes a set amount

The cells students fill in are left blank in this preview.

Every request comes from an identity

In the cloud, every request comes from an identity. It may be a person signing in, or a program such as the invoice service.

Each identity has a policy: a list of permissions. When a request arrives, the provider checks the policy. If the action is not on the list, the answer is no. Give each service its own role, so its rights are its own.

Worked example: the invoice service’s policy

ActionOn whatAllowed?
ReadThe orders tableYes
Writeinvoices/ in the documents bucketYes
Readinvoices/ in the documents bucketYes
DeleteAnythingNo
Start serversAnythingNo

The cells students fill in are left blank in this preview.

Try it: checking a request

Code: python
# The invoice service's policy: what it may do, and nothing else.
policy = ["read:orders", "write:invoices", "read:invoices"]

def allowed(policy, action):
    # The provider says yes only if the action is on the list.
    for rule in policy:
        if rule == action:
            return True
    return False

print("read:orders", allowed(policy, "read:orders"))
print("delete:invoices", allowed(policy, "delete:invoices"))
print("start:servers", allowed(policy, "start:servers"))

# Add "read:customers" to the policy, then check it the same way.

Least privilege: only what the job needs

Least privilege means each identity gets only the rights its job needs. The invoice service writes invoices, so it may not delete them or start servers.

A star, *, in a rule usually means everything. delete:* means delete anything. A star saves typing, but it hands out rights nobody planned. If a key with a star leaks, the stranger gets all of them.

A common mistake

Warning

Many people think full rights for everyone saves time in a small team. It saves a minute today. Then one leaked key or one typing mistake reaches everything in the account. Start with no rights, and add each one when a job needs it.

Four habits keep the bill down

Most surprise bills come from things left running. Four habits help.

Switch off what you are not using, such as test servers at night. Pick the smallest size that does the job. Put a tag (a label you choose, such as team=payroll) on everything, so you can see who spends what. Set a budget alert, so a person hears about a jump the same day, not at the end of the month.

Worked example: one team’s monthly bill

ItemBeforeAfterWhat changed
Test servers£144£32Switched off at night and at weekends
Main server£200£100A smaller size that still copes
Old backups£40£10Moved to a cheaper storage class
Total£384£142Less than half

The cells students fill in are left blank in this preview.

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.