ARO-RP/cmd/aro/main.go

96 строки
2.0 KiB
Go
Исходник Обычный вид История

2019-12-22 20:47:29 +03:00
package main
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"context"
2020-01-21 05:57:53 +03:00
"flag"
"fmt"
"math/rand"
2020-10-14 18:14:20 +03:00
"net/http"
_ "net/http/pprof"
2019-12-22 20:47:29 +03:00
"os"
"strings"
"time"
2019-12-22 20:47:29 +03:00
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"
2019-12-22 20:47:29 +03:00
)
2020-01-21 05:57:53 +03:00
func usage() {
2020-03-22 07:35:17 +03:00
fmt.Fprint(flag.CommandLine.Output(), "usage:\n")
2021-03-30 19:53:33 +03:00
fmt.Fprintf(flag.CommandLine.Output(), " %s dbtoken\n", os.Args[0])
2020-03-22 07:35:17 +03:00
fmt.Fprintf(flag.CommandLine.Output(), " %s deploy config.yaml location\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), " %s mirror [release_image...]\n", os.Args[0])
2020-03-22 07:35:17 +03:00
fmt.Fprintf(flag.CommandLine.Output(), " %s monitor\n", os.Args[0])
2020-09-26 01:20:03 +03:00
fmt.Fprintf(flag.CommandLine.Output(), " %s portal\n", os.Args[0])
2020-03-22 07:35:17 +03:00
fmt.Fprintf(flag.CommandLine.Output(), " %s rp\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), " %s operator {master,worker}\n", os.Args[0])
2020-01-21 05:57:53 +03:00
flag.PrintDefaults()
}
2019-12-22 20:47:29 +03:00
func main() {
rand.Seed(time.Now().UnixNano())
2020-01-21 05:57:53 +03:00
flag.Usage = usage
flag.Parse()
2020-01-19 02:46:58 +03:00
ctx := context.Background()
Collect Audit Logs From RP Frontend (#1243) * Update RP frontend to collect audit logs 1. Add a new middleware to audit inbound requests 2. Requests to the Azure 'operationsstatus' endpoints are skipped 3. Remove the embedded 'env' from the audit log hook to decouple the dependency. The 'env' is passed in to the Audit middleware 4. Replace unnecessary custom string types with basic string types 5. Update the testutil 'AssertLoggingOutput' method to skip asserting audit logs to reduce flakiness in tests. Audit logs assertion is done in a new 'audit.AssertAuditingOutput()' testutil method Signed-off-by: Ivan Sim <isim@redhat.com> * Address Troy's feedback Signed-off-by: Ivan Sim <isim@redhat.com> * Update fluent-bit config with rewrite_tag filter This filter rewrites the input tag of journald logs that have the field LOGKIND=ifxaudit, to ifxaudit. Using a different tag for ifxaudit logs allows us to separate them from non-audit logs in the mdsd configuration. Signed-off-by: Ivan Sim <isim@redhat.com> * Address Jim's feedback Signed-off-by: Ivan Sim <isim@redhat.com> * New changes per discussion with Jim 1. Merge the 'audit' middleware with the 'log' middleware to avoid type assertions 3. Update security_test.go with audit test 4. Remove pointer reference to audit constructor 5. Add new audit log entry to testinfra struct Signed-off-by: Ivan Sim <isim@redhat.com> * Address MJ's feedback 1. Add unit test to test supported URL patterns Signed-off-by: Ivan Sim <isim@redhat.com> * Address Jim's feedback 1. Move adminOp 'if' conditional to log middleware 2. Extract out the 'if' conditional check into a helper function 3. Add start and end symbols to new regex expressions Signed-off-by: Ivan Sim <isim@redhat.com>
2021-02-04 14:09:06 +03:00
audit := utillog.GetAuditEntry()
2019-12-22 20:47:29 +03:00
log := utillog.GetLogger()
2020-10-14 18:14:20 +03:00
go func() {
log.Warn(http.ListenAndServe("localhost:6060", nil))
}()
log.Printf("starting, git commit %s", version.GitCommit)
2019-12-22 20:47:29 +03:00
var err error
2020-03-05 05:02:28 +03:00
switch strings.ToLower(flag.Arg(0)) {
2021-03-30 19:53:33 +03:00
case "dbtoken":
checkArgs(1)
err = dbtoken(ctx, log)
2020-09-26 01:20:03 +03:00
case "deploy":
checkArgs(3)
err = deploy(ctx, log)
2019-12-22 20:47:29 +03:00
case "mirror":
checkMinArgs(1)
2020-01-19 02:46:58 +03:00
err = mirror(ctx, log)
case "monitor":
2020-03-06 13:28:05 +03:00
checkArgs(1)
2020-01-19 02:46:58 +03:00
err = monitor(ctx, log)
2019-12-22 20:47:29 +03:00
case "rp":
2020-03-06 13:28:05 +03:00
checkArgs(1)
Collect Audit Logs From RP Frontend (#1243) * Update RP frontend to collect audit logs 1. Add a new middleware to audit inbound requests 2. Requests to the Azure 'operationsstatus' endpoints are skipped 3. Remove the embedded 'env' from the audit log hook to decouple the dependency. The 'env' is passed in to the Audit middleware 4. Replace unnecessary custom string types with basic string types 5. Update the testutil 'AssertLoggingOutput' method to skip asserting audit logs to reduce flakiness in tests. Audit logs assertion is done in a new 'audit.AssertAuditingOutput()' testutil method Signed-off-by: Ivan Sim <isim@redhat.com> * Address Troy's feedback Signed-off-by: Ivan Sim <isim@redhat.com> * Update fluent-bit config with rewrite_tag filter This filter rewrites the input tag of journald logs that have the field LOGKIND=ifxaudit, to ifxaudit. Using a different tag for ifxaudit logs allows us to separate them from non-audit logs in the mdsd configuration. Signed-off-by: Ivan Sim <isim@redhat.com> * Address Jim's feedback Signed-off-by: Ivan Sim <isim@redhat.com> * New changes per discussion with Jim 1. Merge the 'audit' middleware with the 'log' middleware to avoid type assertions 3. Update security_test.go with audit test 4. Remove pointer reference to audit constructor 5. Add new audit log entry to testinfra struct Signed-off-by: Ivan Sim <isim@redhat.com> * Address MJ's feedback 1. Add unit test to test supported URL patterns Signed-off-by: Ivan Sim <isim@redhat.com> * Address Jim's feedback 1. Move adminOp 'if' conditional to log middleware 2. Extract out the 'if' conditional check into a helper function 3. Add start and end symbols to new regex expressions Signed-off-by: Ivan Sim <isim@redhat.com>
2021-02-04 14:09:06 +03:00
err = rp(ctx, log, audit)
2020-09-26 01:20:03 +03:00
case "portal":
checkArgs(1)
err = portal(ctx, log, audit)
case "operator":
checkArgs(2)
err = operator(ctx, log)
2020-01-19 02:46:58 +03:00
default:
usage()
os.Exit(2)
2019-12-22 20:47:29 +03:00
}
if err != nil {
log.Fatal(err)
}
}
2020-03-06 13:28:05 +03:00
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)
}
}