Golang For DevOps and Cloud Engineers-1
Golang For DevOps and Cloud Engineers-1
What is Go
• From the of cial Go homepage (https://go.dev/):
• I started publishing on Udemy in 2015 and have now more than 250,000
students enrolled in one of my DevOps / Cloud courses
Integrating with
SDKs, Cloud
Understanding Go by
Providers,
example
Go Concepts Kubernetes by
learning how to use
(http-get application)
external packages
(libraries)
GET /words
GET /occurrence
test-server
http-get client
(API server)
POST /login
GET /words
{ “page”: “words”, … }
GET /words
test-server
http-get client
password: xyz
401 Unauthorized
{ “page”: “words”, … }
Array: Slice:
Array: Slice:
7 3 6 0 4 9 10 3 6
Length: 7 Length: 2
Capacity: 7 Capacity: 6
Element 0: arr1[1]
• When not cross compiling, cgo will be enabled, when cross-compiling it’ll be disabled
• This is relevant even if you’re not using this feature yourself, because standard
Go packages like “net” can use cgo (for example for DNS resolving)
• cgo will link your binary to the current C library available on your operating
system, but it’ll not work on an OS with a different C library
CGO_ENABLED=1 go build
glibc/libc/musl
libc system
library
Result is a dynamically linked binary
(External les)
Pure go
implementation
of C libraries CGO_ENABLED=0 go build
• May lead to a binary smaller in size (as C bindings for DNS Resolver,
networking will be in libc/glibc/…)
• You already have the C libraries bundled with your OS, there’s no
need to have them included again in every binary
GET /?Action=DescribeRegions
&AllRegions=true
&AUTHPARAMS
AWS Endpoints
http client ec2.amazonaws.com
s3.amazonaws.com
<DescribeRegionsResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
<regionInfo>
…
</regionInfo>
</DescribeRegionsResponse>
SSHv2
Create Network
Create VM
Interface
• It gives a user a single login & password (and optional MFA capability)
• While very convenient for the end-user, it’s also more secure
• You’d still need to validate the login, password, and potentially MFA token with
a separate mechanism
• SAML 2.0 was released in 2005, while OpenID Connect (OIDC) was launched
in 2015
• SAML is still used a lot, but OpenID Connect is more lightweight and much
easier to implement
Golang For DevOps and Cloud Engineers - Edward Viaene
Why implement OIDC
• It’s a great learning experience
• You’re often exposed to an IdP, and it’s worth understanding the inner
workings
• You can build your own IdP authorization server, client, or application
• Understanding how the how ow works will help you when you need
to build one of these components
• Implicit ow
• Hybrid ow
/authorization?
client_id=1-2-3-4 /token
&redirect_uri=http://localhost:8081/callback
&scope=openid endpoint
&response_type=code
&state=randomstring
User Authorization
Server
/login
/token
endpoint
User Authorization
Server
(Web) Application
POST /token
grant_type=authorization_code
&client_id=1-2-3-4
&client_secret=secret
&redirect_uri=https://
localhost:8081/callback
&code=…
/token
endpoint
User Authorization
Server
(Web) Application
GET /jwks.json
User Authorization
Server
{
"issuer": "http://localhost:8080",
"authorization_endpoint": "http://localhost:8080/authorization",
"token_endpoint": "http://localhost:8080/token",
"userinfo_endpoint": "http://localhost:8080/userinfo",
"jwks_uri": "http://localhost:8080/jwks.json",
"scopes_supported": [
Discovery
],
"oidc" endpoint
"response_types_supported": [
"code"
],
"token_endpoint_auth_methods_supported": [
"none"
]
}
/token
endpoint
User Authorization
Server
/userinfo
(Web) Application
endpoint
GET /userinfo
• The start project contains already the function signatures, and I have
written unit tests for those function to be able to test the validity of your
code
fi
Using OIDC
• Now that we have an OIDC compatible authorization server we can start
adding applications that support OIDC
• There are a lot of (SaaS) applications that support OIDC (often next to SAML)
• There’s also companies that can act as an OIDC Provider itself, like Google,
Apple, Facebook (social media logins have OIDC capabilities)
• You could either use their authorization server and trust their token, or
write an integration to validate a successful social login, and issue your
own token with your own server
• We’ll make AWS trust our IDToken to issue access keys to our users
• The default port for unencrypted http traf c is 80, the default port for
encrypted (https) traf c is 443
• The hostname of the server will be included in the server certi cate
• The server certi cate will be signed by a Certi cate Authority (CA)
• If the client can validate the server certi cate, we can trust the server
• To be able to validate the certi cates, we’ll need to always have the certi cates
of the Certi cate Authorities that can sign the certi cates (also called the root
certi cates)
• Browsers typically have this list built-in, and within Go, it’ll also look for those
les in hardcoded system paths to be able to validate certi cates
Golang For DevOps and Cloud Engineers - Edward Viaene
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
TLS
• This is all client-server communication where the server offers the client a
certi cate that can be validated
• Using a self-signed certi cate (we will issue the Certi cate Authority certi cate
ourselves, so only someone who has this speci c CA certi cate will be able to
validate our server certi cate)
• Using a “real” certi cate issued by a company that can sign with a root
certi cate (DigiCert, GeoTrust, RSA, GlobalSign, …)
• All these approaches can be used for 1-way TLS. For 2-way TLS a self-signed CA is
common, but the other approaches would also work
Golang For DevOps and Cloud Engineers - Edward Viaene
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
TLS
Strategies (self-signed, signed by root CA, Let’s Encrypt)
Self Signed CA
CA Certi cate
Certi cate Certi cate
To validate Server Certi cate Authority Authority
Certi cate Key
TLS
Server Server
Client
Certi cate
Server
Key
Server Server
Client
Certi cate
Server
Key
Server Server
Client
Certi cate
Server
Key
TLS
Client Server
Key Key