In the previous lesson, you saw a Python script that sent a PATCH to R1.
That script usedauth=("admin", "cisco123")andverify=False.
Let's see what each piece does, and why those lines matter in production.What You Already Saw in Your RESTCONF Lab
Here is the script from the RESTCONF lesson, the one that reads the GigabitEthernet1 configuration:
import requests import urllib3 urllib3.disable_warnings() url = "https://192.168.1.1/restconf/data/Cisco-IOS-XE-native:native/interface/GigabitEthernet=1" headers = { "Accept": "application/yang-data+json" } response = requests.get(url, headers=headers, auth=("admin", "cisco123"), verify=False)Three lines in that script touch security:
The
https://URL — your traffic uses an encrypted transportauth=("admin", "cisco123")— your script proves who is callingverify=False— your script skips checking the router's certificate (you should never do that in production)
REST Is a Convention, Not a Shield
REST is a set of rules for how a script and a router talk to each other over HTTP.
It says: GET to read, POST to create, PATCH to modify.But REST says nothing about how to protect that conversation.
REST defines structure, not security. Encryption and authentication are layers added on top of REST.Answer the question below
Does REST itself provide any built-in protection for the data exchanged?
Three Security Questions for Every Call
When your script sends an HTTPS request to R1, three questions must be answered before the call is safe:

Figure 1 – The three security questions
Each question is answered by one section of this lesson.
Miss any one of them and the API is exposed to attack.Answer the question below
What single letter added to http makes the URL use an encrypted transport?
In the lab, you typed
ip http secure-serveron R1.R1# conf t Enter configuration commands, one per line. End with CNTL/Z. R1(config)# ip http secure-server R1(config)# endThis command turned on TLS, the protocol that keeps your traffic safe between the client and the router.
What TLS Does for You
TLS (Transport Layer Security) is the layer between HTTP and TCP.
It does two things for every connection:It encrypts the entire HTTP request and response (anyone sniffing the wire sees only random bytes)

Figure 2 – TLS encrypts the payload on the wire
It verifies the server's identity through a certificate, so your client knows it is talking to R1, not an imposter

Figure 3 – Certificate validation flow
The second point is what
verify=Falseturned off in the lab script.
The certificate check was skipped because R1 used a self-signed certificate.In production, you keep
verify=True.
Otherwise an attacker on the network could impersonate the router and capture the password.Answer the question below
What protocol does HTTPS use to encrypt the tunnel between the client and the server?
The tunnel is encrypted, but R1 still has no idea who sits at the other end.
Authentication is how the client proves its identity before R1 accepts a single command.Basic Auth
Two simple methods work the same way: a credential goes inside an HTTP header, and the server checks it.
The first one is the method you already saw in the lab.The line
auth=("admin", "cisco123")tells the Python library to use HTTP Basic Authentication.
The library takes the username and password, joins them with a colon, and places the result in an Authorization header.
Figure 4 – Python auth tuple to HTTP header
That header travels with every request the script sends.
The string
YWRtaW46Y2lzY28xMjM=isadmin:cisco123written in Base64.
Base64 is an encoding, not encryption.Anyone can reverse it in one command:
$ echo "YWRtaW46Y2lzY28xMjM=" | base64 -d admin:cisco123The credentials come back in clear text.
On plain HTTP, an attacker on the wire grabs the header and reads the password instantly.This is why Basic Auth must always run inside an HTTPS tunnel.
Answer the question below
Is Basic Auth safe to use over plain HTTP?
API Keys
The second method is the API Key.
Instead of a username and password, the client sends a single random string in a custom header likeX-API-Key.
Cisco DNA Center, Meraki Dashboard, and most SaaS platforms generate one for you when you create an account.
Figure 5 – API Key in a custom header
API Keys have two advantages over Basic Auth:
they are not tied to a personal account
you can revoke or rotate them without changing anyone's password.
They share the same weakness, though.
If a key leaks in a Git commit or a screenshot, the attacker keeps full access until someone notices and revokes it.Answer the question below
What encoding makes admin:cisco123 become YWRtaW46Y2lzY28xMjM= ?
OAuth 2.0 for Third-Party Apps
Basic Auth and API Keys handle simple cases well.
But what happens when a third-party application needs to call your API on your behalf?With Basic Auth, you have to give it your admin password.
If the tool is hacked, the attacker has your full admin credentials.OAuth Principle
OAuth 2.0 (RFC 6749) fixes this with a different model.
The tool gets a limited-scope access token instead of your password.
Figure 6 – OAuth 2.0 token flow
Three actors are involved:
App — the client that wants to call the API
Authorization server — the server that validates credentials and issues tokens
Resource API — the actual API the app wants to use, like a router or a controller
The app sends the credentials to the authorization server, which returns an access token.
Every subsequent call to the resource API carries that token in anAuthorization: Bearer ...header.Tokens expire (typically after one hour), they can be limited to a specific scope, and you can revoke them at any time.
The app never sees the user's password.If the app is compromised, the attacker only gets a token that expires within an hour, not your full admin account.
Answer the question below
With OAuth 2.0, does the third-party app ever see the user's password?
JWT, the Token Format
OAuth defines how to get a token, not what the token contains.
The format you encounter most often is the JSON Web Token (RFC 7519), or JWT.A JWT looks like a single long string, but it splits into three parts separated by dots:

Figure 7 – JWT split into three parts
Each part has a clear role:
Header — describes the token type and the signing algorithm
Payload — contains claims about the user (identity, scope, expiration)
Signature — proves the token was issued by the authorization server and was not modified
Header and payload are Base64-encoded, the same Base64 you just decoded.
Answer the question below
Is the payload of a JWT encrypted?
You can decode any JWT yourself.
Try it on a sample token to see what's inside:$ echo "eyJzdWIiOiJhZG1pbiIsInNjb3BlIjoicmVhZCJ9" | base64 -d {"sub":"admin","scope":"read"}What protects a JWT is not encryption. It is the signature.
If an attacker modifies the payload, for example changingscope: readintoscope: admin, the signature no longer matches and the server rejects the token.Never put secrets in a JWT payload.
Anyone holding the token can read it.Answer the question below
How many parts does a JWT contain, separated by dots?
You know who is calling.
One question remains: what are they allowed to do?
Authentication tells you who someone is.
Authorization tells you what they can access.Same Identity, Different Rights
Take two users on a DNA Center:
A monitoring user who reads dashboards and alerts.
A network admin who pushes interface descriptions and routing changes.
Both are legitimate users.
But they need very different access:Monitoring User
If the monitoring user's token leaks, the attacker can read dashboards. Nothing more.
They cannot push a malicious config to your routers because the token's scope blocks write operations.
Figure 8 – Read scope: PATCH rejected
The damage is contained.
Network Admin
Now switch to the network admin side.
They have a token with full scope and can push any configuration.
Figure 9 – Admin scope: PATCH succeeds
That is why every well-designed API enforces the principle of least privilege.
Least privilege limits the impact of a leaked token.
Give each user only the rights their job needs. Nothing more.Security Design Principles
Three security principles apply directly to REST API authorization:
Principle
What it means
Example
Least privilege
Each user or token gets only the rights needed for the task
Read-only token for the NOC, admin token for operators
Fail-safe defaults
By default, access is denied. Permissions are granted explicitly
A new user starts with zero scopes until you assign one
Complete mediation
Every single request is checked against the authorization rules
A revoked token stops working immediately, not after a cache expires
Table 1 – Three security design principles applied to REST APIs
These principles are not specific to REST APIs.
They apply to any system where access must be granted, from a router with local users to an enterprise IAM platform.Answer the question below
Which security design principle states that, by default, a user has no access to any resource?