Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jonachang/helmid #3253

Open
wants to merge 189 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
e3446d1
add poc tot usage
Aug 9, 2023
07398cb
minor fix
Aug 9, 2023
72ee450
POC hello world
Aug 9, 2023
dd0f39e
POC dockerfile
Aug 10, 2023
7f71c3d
update poc dockerfile
Aug 10, 2023
1ce0ed9
no e2e needed
Aug 10, 2023
357835b
Merge branch 'master' into niontive/aks-poc
Aug 15, 2023
3ce3309
save work
Aug 15, 2023
66c8812
fix helm
Aug 16, 2023
3676abd
save work
Aug 17, 2023
ae907a2
remove tgz
Aug 17, 2023
4a2d841
service account
Aug 17, 2023
ed48785
Merge branch 'master' into niontive/aks-poc
Aug 18, 2023
4b42aee
save work
Aug 21, 2023
f030348
save work
Aug 21, 2023
e8baee2
save work
Aug 21, 2023
538625a
nit fix
Aug 21, 2023
987b50d
nit fix
Aug 21, 2023
fca0cca
Add README
Aug 21, 2023
095053b
readme
Aug 21, 2023
70e0a83
pipefail
Aug 22, 2023
c3f1503
Merge pull request #2 from niontive/niontive/aks-poc-build
jonathan34c Aug 22, 2023
21a8c30
add gateway
Aug 18, 2023
b864c04
add namespace
Aug 18, 2023
f75850a
add label
Aug 18, 2023
ebafe37
add credential
Aug 21, 2023
8a16478
add pkg
Aug 21, 2023
9942b5b
make tar
Aug 21, 2023
27a9b6a
remove values
Aug 21, 2023
9023146
use value.yaml
Aug 22, 2023
f81bd1d
fix credential
Aug 22, 2023
c470593
remove namesapce
Aug 22, 2023
8aa1e51
edit crt and key
Aug 22, 2023
54ea5e9
rename secret
Aug 22, 2023
d474ecd
change name
Aug 22, 2023
d71a2cc
add comments
Aug 22, 2023
0ed0120
remove secret crt and key
Aug 22, 2023
429bf08
git add comment
Aug 22, 2023
7356331
remove unused file
Aug 22, 2023
0d91b17
remove tls secret
Aug 23, 2023
705d7df
change to poc port
Aug 23, 2023
c1e1848
fix helm lint
Aug 23, 2023
7670c6e
Merge pull request #1 from niontive/jonachang/gateway
niontive Aug 23, 2023
7f2475f
Only expose port 8080
Aug 24, 2023
758cd5d
save work
Aug 24, 2023
58bd87c
Merge pull request #3 from niontive/niontive/aks-poc-rp
jonathan34c Aug 24, 2023
92b3763
Merge branch 'master' into niontive/aks-poc
niontive Aug 29, 2023
64d9a50
Merge branch 'master' into niontive/aks-poc
Sep 5, 2023
1676571
Merge branch 'niontive/aks-poc' of https://github.com/niontive/ARO-RP…
Sep 5, 2023
adfe2dc
Make protocl HTTP for now
Sep 6, 2023
cfb0293
remove unused ingress
Sep 6, 2023
96eafd1
update service
Sep 6, 2023
7dad5b3
save work
Sep 6, 2023
4dd7901
Fix probe port
Sep 7, 2023
07e9434
save work
Sep 7, 2023
34b2dbc
sidecar injection
Sep 7, 2023
3933b2f
save work
Sep 7, 2023
1aefd36
save work
Sep 7, 2023
ada5228
save work
Sep 7, 2023
8cd1b87
nix
Sep 7, 2023
2c3df60
Merge pull request #4 from niontive/niontive/aks-poc-service
jonathan34c Sep 7, 2023
a7eb141
first draft
Sep 20, 2023
68f3433
x
Sep 21, 2023
96d4adb
change secret name
Sep 21, 2023
56a306f
rename secret provider
Sep 21, 2023
536c88c
Merge pull request #5 from niontive/jonachang/provider
jonathan34c Sep 21, 2023
15e433d
add tls pod
Sep 21, 2023
758ec44
change clientid
Sep 21, 2023
ec34df2
change pod name
Sep 22, 2023
e1e6949
change contianer name
Sep 22, 2023
51efa35
rename to aks pod
Sep 26, 2023
cc00a41
change value
Sep 27, 2023
14028f6
move to deployment
Sep 27, 2023
bb98daf
fix format
Sep 27, 2023
1c37e90
move volumes
Sep 27, 2023
a5f3561
create sync pod
Sep 29, 2023
c32e0ca
remove namespace
Oct 2, 2023
39a5b0e
add secret provider to istio-ststem
Oct 2, 2023
78dffd1
update tls mode and change port
Oct 2, 2023
2876fe0
change to deployment
Oct 2, 2023
716736d
change value
Oct 2, 2023
9d54560
redu
Oct 3, 2023
45c8c57
remove space
Oct 3, 2023
45df1a1
add port
Oct 3, 2023
ce7eec9
remove unused volume
Oct 4, 2023
adfe1e2
add value back
Oct 4, 2023
b4293f1
change deployment
Oct 4, 2023
879e24d
add user assign identity back
Oct 5, 2023
906d5f8
remove id
Oct 5, 2023
350fe17
remove port
Oct 9, 2023
440f680
https gateway
Oct 10, 2023
e5381a7
Update namespace for secret
Oct 11, 2023
8cafacb
nit
Oct 11, 2023
d4cdfef
Merge pull request #6 from niontive/jonachang/pod
niontive Oct 11, 2023
8fed6de
add test message
Oct 12, 2023
0dd5808
add mise
Oct 12, 2023
3704f70
change image
Oct 13, 2023
0be84cf
update mise image
Oct 16, 2023
677c176
change svc
Oct 16, 2023
85706d1
change structuree
Oct 16, 2023
660cd11
combine deployment
Oct 16, 2023
cf8454e
change to mise
Oct 16, 2023
afda35f
edit appsettings
Oct 16, 2023
a4d5791
add testing words
Oct 16, 2023
49299fa
add mise
Oct 17, 2023
ad3bc74
add mise
Oct 17, 2023
86f9cc6
move constant to value.taml
Oct 17, 2023
19a2c41
change log level to debug
Oct 17, 2023
a886753
remove comment
Oct 17, 2023
618e5e0
add authority
Oct 17, 2023
0c2ede0
fix json
Oct 17, 2023
6592b87
add log level
Oct 18, 2023
473dc79
change log level
Oct 18, 2023
05eb42a
change debug level
Oct 18, 2023
f50e4c1
change config
Oct 18, 2023
b03ee22
add double quotation
Oct 18, 2023
66e44e2
add quotation
Oct 18, 2023
e6f5fde
ad bearer
Oct 18, 2023
65fa4a0
add log
Oct 18, 2023
1c2ef52
add loglevel
Oct 19, 2023
b59a696
add keyback
Oct 19, 2023
3530d42
add comments in yaml
Oct 19, 2023
ea8a994
follow aks
Oct 19, 2023
85892a5
remove comment
Oct 19, 2023
6a98dfc
remove error loglevel
Oct 19, 2023
beb1ac1
fix comments
Oct 19, 2023
adbfc7d
fix comments
Oct 19, 2023
24b40bd
Merge pull request #7 from niontive/jonachang/mise
niontive Oct 19, 2023
c3b9e50
Merge branch 'master' into niontive/aks-poc
Oct 23, 2023
336fafe
add flag
Oct 25, 2023
63b8389
add flag
Oct 25, 2023
e5cfdcb
update tgz
Oct 25, 2023
5a2d589
add main
Oct 25, 2023
e958f5b
add text
Oct 26, 2023
70d4a68
add mise auth
Oct 26, 2023
519cdcf
add logs
Oct 26, 2023
3aec3f2
change local
Oct 26, 2023
3829ffb
add log and change url
Oct 27, 2023
e0a96ed
update config
Oct 27, 2023
c958fb7
fix comments
Oct 27, 2023
79428ba
add miseauth
Oct 27, 2023
d600a3f
remove unused
Oct 27, 2023
2af41d3
add token type back
Oct 30, 2023
3716957
fix comment
Oct 31, 2023
98230d7
remove pkg
Oct 31, 2023
b29280a
add README
Nov 8, 2023
b1ebf4a
change mise switch to off
Nov 8, 2023
76ac9df
test if false would work
Nov 8, 2023
5ded4f1
reenable MISE
Nov 8, 2023
dc80c37
Make entrypoint just aro
Nov 10, 2023
60fb4ce
Update comment
Nov 10, 2023
9bf817c
Update deployment.yaml
Nov 10, 2023
17817b8
simplify aro command for poc
Nov 10, 2023
bfd2bec
Add back dbname
Nov 10, 2023
ee0f953
add mise switch to dockerfile
Nov 10, 2023
5d5db4e
add flag
Nov 13, 2023
9e24398
fix error
Nov 13, 2023
7b1b0f8
Fix flag parse
Nov 13, 2023
fe009f9
add checklog
Nov 13, 2023
d2dc266
remove logs
Nov 14, 2023
bd4ed97
remove unused
Nov 14, 2023
08fa552
fix nit
Nov 14, 2023
263f0bd
change ocntext
Nov 14, 2023
d3cf124
Merge pull request #8 from niontive/jonachang/miseauth
niontive Nov 14, 2023
190ed35
erge branch 'niontive/aks-poc' into niontive/aks-poc-deploy
Nov 14, 2023
8d65ed5
Cleanup code
Nov 14, 2023
caca367
Update deployment
Nov 14, 2023
a3ffa42
frontend nit
Nov 14, 2023
7c93b03
remove comment
Oct 30, 2023
cc6748e
add internal policy
Nov 14, 2023
d410429
combine policy
Nov 15, 2023
32822e8
add log
Nov 15, 2023
6cf6d0b
test ids
Nov 15, 2023
ccccd7c
edit mise
Nov 15, 2023
12403a5
test
Nov 15, 2023
271267c
fix mise
Nov 16, 2023
41a6ad7
add more log
Nov 16, 2023
cacce43
try another deploy
Nov 16, 2023
7a7e88c
change authority
Nov 16, 2023
8e8baea
test
Nov 16, 2023
5b3f8bb
informative log
Nov 16, 2023
32b6bfd
add method back
Nov 16, 2023
e6c93d2
add inboundpolicy and rebase
Nov 16, 2023
352450a
add back changed
Nov 16, 2023
90bdfba
Don't export MISE request data for now
Nov 16, 2023
d9c4b02
fix auth with mise
Nov 16, 2023
a579262
nit
Nov 17, 2023
4b6e3c6
Merge pull request #10 from niontive/niontive/aks-poc-deploy
niontive Nov 17, 2023
065b7f1
revaseremove clientid
Oct 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Dockerfile.aro-poc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Build container for POC usage
ARG REGISTRY
FROM ${REGISTRY}/ubi8/ubi-minimal
RUN microdnf update && microdnf clean all
RUN curl -o /etc/pki/ca-trust/source/anchors/AMEROOT_ameroot.crt http://crl.microsoft.com/pkiinfra/certs/AMEROOT_ameroot.crt && update-ca-trust
COPY ./aro /usr/local/bin/
ENTRYPOINT ["aro"]
# Endpoint used for healthz. We may also use this endpoint for HTTP handler (configurable)
EXPOSE 8080/tcp
USER 1000
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,9 @@ vendor:
hack/update-go-module-dependencies.sh

.PHONY: admin.kubeconfig aks.kubeconfig aro az clean client deploy dev-config.yaml discoverycache generate image-aro image-aro-multistage image-fluentbit image-proxy lint-go runlocal-rp proxy publish-image-aro publish-image-aro-multistage publish-image-fluentbit publish-image-proxy secrets secrets-update e2e.test tunnel test-e2e test-go test-python vendor build-all validate-go unit-test-go coverage-go validate-fips

poc-pkg:
helm package poc/pkg

poc-build-deploy:
poc/hack/build-deploy.sh $(alias)
91 changes: 12 additions & 79 deletions cmd/aro/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,104 +5,37 @@ package main

import (
"context"
"flag"
"fmt"
"math/rand"
"net/http"
_ "net/http/pprof"
"os"
"strings"
"time"

"github.com/Azure/ARO-RP/pkg/env"
utillog "github.com/Azure/ARO-RP/pkg/util/log"
_ "github.com/Azure/ARO-RP/pkg/util/scheme"
"github.com/Azure/ARO-RP/pkg/util/version"
"github.com/spf13/pflag"
)

func usage() {
fmt.Fprint(flag.CommandLine.Output(), "usage:\n")
fmt.Fprintf(flag.CommandLine.Output(), " %s dbtoken\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), " %s deploy config.yaml location\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), " %s gateway\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), " %s mirror [release_image...]\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), " %s monitor\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), " %s portal\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), " %s rp\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), " %s operator {master,worker}\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), " %s update-versions\n", os.Args[0])
flag.PrintDefaults()
var (
serverPort string
enableMISE bool
)

func init() {
pflag.StringVar(&serverPort, "server-port", "8080", "port to service http requests")
pflag.BoolVar(&enableMISE, "enable-mise", false, "enable MISE authentication for http requests")
}

func main() {
rand.Seed(time.Now().UnixNano())
pflag.Parse()

flag.Usage = usage
flag.Parse()

ctx := context.Background()
audit := utillog.GetAuditEntry()
log := utillog.GetLogger()

go func() {
log.Warn(http.ListenAndServe("localhost:6060", nil))
}()

log.Printf("starting, git commit %s", version.GitCommit)

var err error
switch strings.ToLower(flag.Arg(0)) {
case "dbtoken":
checkArgs(1)
err = dbtoken(ctx, log)
case "deploy":
checkArgs(3)
err = deploy(ctx, log)
case "gateway":
checkArgs(1)
err = gateway(ctx, log)
case "mirror":
checkMinArgs(1)
err = mirror(ctx, log)
case "monitor":
checkArgs(1)
err = monitor(ctx, log)
case "rp":
checkArgs(1)
err = rp(ctx, log, audit)
case "portal":
checkArgs(1)
err = portal(ctx, log, audit)
case "operator":
checkArgs(2)
err = operator(ctx, log)
case "update-versions":
checkArgs(1)
err = updateOCPVersions(ctx, log)
default:
usage()
os.Exit(2)
}

if err != nil {
ctx := context.Background()
if err := rpPoc(ctx, log); err != nil {
log.Fatal(err)
}
}

func checkArgs(required int) {
if len(flag.Args()) != required {
usage()
os.Exit(2)
}
}

func checkMinArgs(required int) {
if len(flag.Args()) < required {
usage()
os.Exit(2)
}
}

func DBName(isLocalDevelopmentMode bool) (string, error) {
if !isLocalDevelopmentMode {
return "ARO", nil
Expand Down
40 changes: 40 additions & 0 deletions cmd/aro/poc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"context"
"os"
"os/signal"
"syscall"

"github.com/Azure/ARO-RP/pkg/poc"
"github.com/sirupsen/logrus"
)

// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.

func rpPoc(ctx context.Context, log *logrus.Entry) error {
log.Print("********** ARO-RP on AKS PoC **********")
ctx, shutdown := context.WithCancel(ctx)
defer shutdown()
go handleSigterm(log, shutdown)

config := poc.FrontendConfig{
Port: serverPort,
EnableMISE: enableMISE,
}

frontEnd := poc.NewFrontend(log, config)

return frontEnd.Run(ctx)
}

func handleSigterm(log *logrus.Entry, shutdown context.CancelFunc) {
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGTERM)
<-signals

log.Print("received SIGTERM. Terminating...")

shutdown()
}
113 changes: 113 additions & 0 deletions pkg/poc/frontend.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package poc

import (
"context"
"fmt"
"log"
"net/http"
"strings"

"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/sirupsen/logrus"
)

// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.

type FrontendConfig struct {
Port string
// TODO(jonachang) delete this in production
EnableMISE bool
}

type frontend struct {
logger *logrus.Entry
port string
router chi.Router
}

func NewFrontend(logger *logrus.Entry, config FrontendConfig) frontend {
var router chi.Router
if config.EnableMISE {
router = getMiseRouter()
} else {
router = getNonMiseRouter()
}

return frontend{
logger: logger,
port: config.Port,
router: router,
}
}

func (f *frontend) Run(ctx context.Context) error {
router := f.router
server := &http.Server{
Addr: ":" + f.port,
Handler: router,
ErrorLog: log.New(f.logger.Writer(), "", 0),
}

go func() {
f.logger.Info("Starting http server...")
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
f.logger.Fatalf("Server listen/serve error: %s", err)
}
}()

<-ctx.Done()

f.logger.Info("Stopping http server")
err := server.Shutdown(context.Background())
if err != nil {
f.logger.Errorf("Server shutdown error: %s", err)
}

return err
}

func getBaseRouter() chi.Router {
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Get("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
w.Write([]byte("ok"))
})
return r
}

func getMiseRouter() chi.Router {
r := getBaseRouter()
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
miseToken := extractAuthBearerToken(r.Header)
miseRespCode, miseRespBody, err := authenticateWithMISE(r.Context(), miseToken, r.Method)
if err != nil {
err = fmt.Errorf("unable to perform authentication with MISE: %s", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if miseRespCode != http.StatusOK {
err = fmt.Errorf("MISE authentication failed with code %d and body %s", miseRespCode, miseRespBody)
http.Error(w, err.Error(), miseRespCode)
return
}
w.Write([]byte("****** Welcome to ARO-RP on AKS PoC mise ******"))
})
return r
}

func getNonMiseRouter() chi.Router {
r := getBaseRouter()
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("****** Welcome to ARO-RP on AKS PoC no mise ******"))
})
return r
}

func extractAuthBearerToken(h http.Header) string {
auth := h.Get("Authorization")
token := strings.TrimPrefix(auth, "Bearer ")
return strings.TrimSpace(token)
}
62 changes: 62 additions & 0 deletions pkg/poc/miseAuthentication.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package poc

import (
"bytes"
"context"
"fmt"
"io"
"net/http"
)

type miseRequestData struct {
MiseURL string
OriginalURI string
OriginalMethod string
Token string
}

const (
miseURL = "http://localhost:5000/ValidateRequest"
originURI = "https://server/endpoint"
)

func authenticateWithMISE(ctx context.Context, token, requestMethod string) (int, string, error) {

requestData := miseRequestData{
MiseURL: miseURL,
OriginalURI: originURI,
OriginalMethod: requestMethod,
Token: token,
}

req, err := createMiseHTTPRequest(ctx, requestData)
if err != nil {
return 0, "", err
}

// TODO(jonachang): need to cache the client when in production.
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return 0, "", err
}
defer resp.Body.Close()

bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return 0, "", fmt.Errorf("error reading response body: %w", err)
}

return resp.StatusCode, string(bodyBytes), nil
}

func createMiseHTTPRequest(ctx context.Context, data miseRequestData) (*http.Request, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodPost, data.MiseURL, bytes.NewBuffer(nil))
if err != nil {
return nil, err
}
req.Header.Set("Original-URI", data.OriginalURI)
req.Header.Set("Original-Method", data.OriginalMethod)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", data.Token))
return req, nil
}
18 changes: 18 additions & 0 deletions poc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Feature
This project is part of the [migration tasks](https://dev.azure.com/msazure/AzureRedHatOpenShift/_wiki/wikis/AzureRedHatOpenShift.wiki/515448/Migration) to migrate the RP application from VMSS to the AKS Cluster and follow the [design](https://dev.azure.com/msazure/AzureRedHatOpenShift/_wiki/wikis/AzureRedHatOpenShift.wiki/567165/Mock-RP-Design).

# Pipelines (Build & Release)
- [RP Infrastructure - INT](https://dev.azure.com/msazure/AzureRedHatOpenShift/_build?definitionId=321081)

# Resources
- Deployment:
- Set up the cluster and deploy the RP application.
- [Istio](https://dev.azure.com/msazure/AzureRedHatOpenShift/_wiki/wikis/AzureRedHatOpenShift.wiki/499024/Istio):
- Follow [AKS Instruction](https://learn.microsoft.com/en-us/azure/aks/istio-about) to implement the Istio addon for the AKS cluster.
- Use it to create an Istio service mesh and gateway for the RP application.
- [TLS Certificate](https://learn.microsoft.com/en-us/azure/aks/ingress-tls?tabs=azure-cli):
- Use the [CSI driver](https://learn.microsoft.com/en-us/azure/aks/csi-secrets-store-driver) to synchronize the Key Vault certificate to AKS.
- Create a dummy pod in the `aks-istio-ingress` namespace to synchronize the certificate using the CSI driver.
- [MISE](https://identitydivision.visualstudio.com/DevEx/_git/MISE?path=%2Fdocs%2FContainer.md&_a=preview):
- Currently, follow the [sidecar pattern](https://dev.azure.com/msazure/AzureRedHatOpenShift/_wiki/wikis/AzureRedHatOpenShift.wiki/595474/MISE-istio-external-authorization-V.S.-side-car-pattern) to implement MISE.
- To enable MISE authentication, edit the `values.yaml`'s `MISE_AUTH_ENABLED` attribute and `enableMISE` in `pkg>poc>miseAuthentication.go` to be either true or false.
8 changes: 8 additions & 0 deletions poc/hack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Scripts for ARO-RP on AKS POC

## build-deploy.sh
- Used to build and deploy ARO-RP from local environment to the test AKS cluster
- Run this via the Makefile.
- In the root ARO-RP directory, run `make alias=*your_alias* poc-build-deploy`
- This will upload your local RP image to the ACR as `dev/*your_alias*:latest`
- This will create a namespaces `*your_alias*-dev` where the local RP build will be deployed
Loading
Loading