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

[v8] Client Certificate Authentication for GCP Cloud SQL #10058

Closed
wants to merge 207 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
207 commits
Select commit Hold shift + click to select a range
5284ad4
Updated webassets reference.
russjones Oct 26, 2021
49495ef
Pin Packer version to 1.7.6
russjones Oct 20, 2021
86642ff
Release 8.0.0-beta.1.
russjones Oct 26, 2021
bcac1c1
Fix event code duplication for PrivilegeTokenCreateCode (#8733) (#8743)
kimlisa Oct 26, 2021
1ce2da1
Add Rust to buildbox
zmb3 Oct 26, 2021
ddcfa54
Stop linking lcrypto and lssl
zmb3 Oct 27, 2021
8403f8b
Update e to match branch/v8
zmb3 Oct 27, 2021
b46b31b
Release 8.0.0-dev.33
zmb3 Oct 27, 2021
0f72bd8
Ensure that Rust libraries are cleaned
zmb3 Oct 27, 2021
a11141b
Update e
zmb3 Oct 27, 2021
8383bda
Release 8.0.0-beta.2.
russjones Oct 27, 2021
1c2cc1e
URL-encode Postgres username in connection string (#8772)
r0mant Oct 28, 2021
f51aa6d
Add link to Teleport Changelog in helm chart repository site. (#8780)
Joerger Nov 1, 2021
0f71ec5
Update mac builds
zmb3 Oct 29, 2021
7b3edf9
Remove checking for error from session end in web terminal (#8797) (#…
kimlisa Nov 2, 2021
7c6e9c2
Fix reverse tunnel web ping call log severity (#8776)
smallinsky Nov 2, 2021
0147761
Set user verification to "discouraged" for WebAuthn (#8759) (#8801)
codingllama Nov 2, 2021
f1a9003
[ami] Get wildcard DNS cert when using certbot/Letsencrypt with Terra…
webvictim Nov 2, 2021
b83c4a6
[helm] Change path -> mountPath under extraVolumeMounts (#8806) (#8825)
webvictim Nov 2, 2021
f20adab
Update rdp-rs to fix horizontal scroll + extended keys
zmb3 Oct 29, 2021
bedecac
Fix mongo access with mfa and add tests (#8800)
r0mant Nov 3, 2021
47ceacd
Bring back previous u2f challenge response for web terminal (#8830) (…
kimlisa Nov 3, 2021
5f0c578
flips struct ordering to match with tdp spec (#8753) (#8814)
Nov 3, 2021
fc7da89
comment out teleport configure output example (#8856)
stevenGravy Nov 4, 2021
f92fde0
Add dynamic registration and discovery guides (#8862)
r0mant Nov 4, 2021
9d5b079
Updated Go to 1.17.3.
russjones Nov 5, 2021
06707a9
Update Enterprise reference.
russjones Nov 5, 2021
f3962c4
Release 8.0.0-beta.3.
russjones Nov 5, 2021
5fcf71b
Split auth.AccessPoint into variant specific interfaces (#8471) (#8859)
rosstimothy Nov 5, 2021
cc469b5
Disable desktop access in Web UI in Cloud clusters (#8858) (#8873)
justinas Nov 5, 2021
d8cea6d
Fix MFA for DB Access (#8796) (#8870)
smallinsky Nov 5, 2021
8f5f69e
Fix tsh ssh proxy (#8826) (#8871)
smallinsky Nov 5, 2021
7e37143
Don't allow running Desktop Access in FIPS mode.
russjones Nov 5, 2021
ac07dbf
Fix ACME strict ALPN (#8869) (#8889)
smallinsky Nov 8, 2021
aabae26
Release 8.0.0-rc.1.
russjones Nov 10, 2021
e5a6744
Return created date with new recovery codes (#8777) (#8903)
kimlisa Nov 10, 2021
4720ef7
Fix the client idle disconnect audit event for desktops
zmb3 Nov 2, 2021
cfa9fbd
Fix heartbeat for LDAP hosts
zmb3 Nov 3, 2021
3c9e332
Use cgo.Handle for passing client refs between Rust/Go
zmb3 Oct 22, 2021
a786ab9
Rust & Desktop Access fixes (#8822)
xacrimon Nov 5, 2021
ede8640
remove roletester toolchain
xacrimon Nov 5, 2021
742da62
fix buildbox
xacrimon Nov 5, 2021
d310de5
Fix the buildbox (again) (#8892)
xacrimon Nov 8, 2021
1322696
Link libatomic on Linux
zmb3 Nov 9, 2021
a85033e
[auto] Update webassets in branch/v8 (#8911)
kimlisa Nov 10, 2021
146c57d
Improve SSH agent forwarding error message in proxy mode (#8832)
codingllama Nov 10, 2021
d5d238f
Update e-ref (#8927)
kimlisa Nov 10, 2021
f5accaa
tctl: allow issuing app access certificates via `tctl auth sign` (#87…
justinas Nov 11, 2021
fb62bdc
windows ldaps port (#8932)
Nov 12, 2021
d00d68a
[auto] Update webassets in branch/v8 (#8965)
kimlisa Nov 12, 2021
61c7c5f
Fix KUBECONFIG server name (#8940) (#8971)
smallinsky Nov 12, 2021
0397b4c
Merge 'config-proxy' and 'proxy ssh' commands logic (#8920) (#8958)
smallinsky Nov 12, 2021
b478e41
backport bot improvements
quinqu Nov 12, 2021
79e4607
Updated CHANGELOG.md.
russjones Nov 12, 2021
cf15ad7
Release 8.0.0-rc.2.
russjones Nov 12, 2021
f39c9ac
Remove explicit "deny" from preset "auditor" role, make preset roles …
justinas Nov 15, 2021
d9cadf3
Updated build-darwin-* pipeline.
russjones Nov 13, 2021
db49852
Fix tunnel address for TLS routing if public tunnel address is presen…
smallinsky Nov 15, 2021
75f248b
Fix dialing kube trusted cluser in v2 telport config (#8996)
smallinsky Nov 15, 2021
da4ebf3
Release 8.0.0-rc.3.
russjones Nov 15, 2021
6720c97
Release 8.0.0.
russjones Nov 16, 2021
4618ab3
[pr-buddy] helm: Add support for annotation on secrets generated by c…
webvictim Nov 16, 2021
3575ec5
Fixed Helm publishing.
russjones Sep 28, 2021
f5ce857
Updated Docker Quickstart/Labs.
russjones Nov 16, 2021
4d574ea
Add meta redirect (#8980)
atburke Nov 18, 2021
778168d
Add --public-addr --cert-file --key-file for teleport configure (#9049)
greedy52 Nov 18, 2021
174460a
teleport configure: generate web_listen_addr (#9071)
greedy52 Nov 19, 2021
b664c6a
Restart entire node on tunnel collapse (#8102) (#9043)
tcsc Nov 19, 2021
e04c246
Update CODEOWNERS (#9058)
quinqu Nov 21, 2021
9a7fbc7
Add app metatada to app audit events (#9056)
gabrielcorado Nov 22, 2021
213df34
Update docs for TLS routing (#9097)
r0mant Nov 22, 2021
7ee2c11
Make Teleport startup resilient to invalid roles (#9062) (#9105)
codingllama Nov 23, 2021
705478c
Implement where conditions for active sessions (#9040) (#9076)
codingllama Nov 23, 2021
4d1a599
Add '+' to key sanitizer whitelist (#8396)
atburke Oct 28, 2021
e917230
Refresh getting started guide to use TLS routing (#8988) (#9101)
klizhentas Nov 26, 2021
d4d7901
Fix MySQL proxy handshake (#9162)
r0mant Dec 1, 2021
e8fee61
[Backport] Google CloudBuild support (#9090) (#9165)
tcsc Dec 1, 2021
766f261
Add Azure access token auth support for Postgres/MySQL (#9185)
r0mant Dec 2, 2021
7839d6c
Update Workflow Config Files (#9207)
quinqu Dec 2, 2021
ede24a0
Bump x/crypto (#9203)
r0mant Dec 3, 2021
66bbd05
Do not prompt for hardware MFA using `tsh` on Windows (#9081) (#9198)
codingllama Dec 3, 2021
5123b3f
[v8]: desktop access backports (#9201)
zmb3 Dec 3, 2021
b95fb53
Release 8.0.1 (#9223)
r0mant Dec 3, 2021
a16bd1f
Fix tsh ssh proxy for openssh client (#9249)
smallinsky Dec 6, 2021
62bccf2
[backport v8] Fix sessions endpoint and remove namespaces (#9360)
rudream Dec 13, 2021
c0ee245
Add support for configurable KMS CMK keys for S3 SSE (#8354) (#9262)
xacrimon Dec 13, 2021
f630d06
Release 8.0.4 (#9368)
r0mant Dec 13, 2021
3389e02
Drone fix (#84)
r0mant Dec 7, 2021
1e123b5
Fix the CRL distribution point in Windows certs (#9299)
zmb3 Dec 9, 2021
0e304c3
Release 8.0.5
r0mant Dec 13, 2021
410edb0
Ensure we don't miss the resolution of an access request (#9193) (#9338)
espadolini Dec 14, 2021
c1fe312
Post Release 1/4 (#9005)
russjones Dec 14, 2021
6975fa5
[v8] Add ability to run Postgres and Mongo proxy on separate listener…
smallinsky Dec 14, 2021
c202945
Add WebAuthn and Active Session docs (#9390)
codingllama Dec 14, 2021
af90b29
[auto] Update webassets in branch/v8
rudream Dec 13, 2021
dd80e8c
Update AWS CLI application access docs ref (#8634) (#9396)
smallinsky Dec 14, 2021
a350fed
Updated CHANGELOG.md.
russjones Dec 14, 2021
807c6d6
Release 8.0.6.
russjones Dec 14, 2021
3c90983
Fix confusing port example in standalone docs
webvictim Nov 23, 2021
420f381
Update which pull request events to trigger workflow on
quinqu Dec 7, 2021
4a11cc8
Don't run workflows on draft PRs
quinqu Dec 7, 2021
827d24d
Trigger on ready_for_review event
quinqu Dec 8, 2021
d41e8d3
Add synchronize event
quinqu Dec 9, 2021
c15dd32
Clear web terminal when session ends (#8850)
atburke Dec 2, 2021
34a091c
Change invalid TOTP message
mcbattirola Dec 1, 2021
19a68e4
Fix NO_PROXY addr logic (#9287) (#9394)
smallinsky Dec 15, 2021
ac6b6f0
Do not parse MySQL server packets (#9411)
r0mant Dec 15, 2021
913a881
[v8] Prevent infinite dialing to Auth (#9403)
rosstimothy Dec 15, 2021
4105120
Add Videos to Teleport Desktop Access (#9374)
benarent Dec 15, 2021
0775475
Avoid "Entering/Leaving directory" output in Make (#9246) (#9424)
justinas Dec 16, 2021
63fcd50
Clarify the Linux Getting Started guide (#9429)
ptgott Dec 16, 2021
45c4540
[Backport v8] Create a blast radius reduction guide (#9430)
ptgott Dec 16, 2021
0cd95f7
[branch/v8] Backport #8840 (#9395)
xacrimon Dec 17, 2021
e06874c
feat: ListResources gRPC rpc (#9096) (#9458)
gabrielcorado Dec 17, 2021
d1f8fa2
Fix app server goroutine leak (#9332) (#9459)
jimbishopp Dec 17, 2021
19c2114
Fix CryptoRandomHex function (#9186) (#9433)
jimbishopp Dec 17, 2021
20626f7
simplify desktop access getting started guide (#9100) (#9467)
Dec 17, 2021
990625d
Update aws-console.mdx (#9480)
pschisa Dec 17, 2021
2f08e0b
Updated Enterprise reference.
russjones Dec 17, 2021
fda9e59
Added support for buildings CentOS 7 RPMs.
russjones Dec 17, 2021
c0a1e07
Update Drone pipeline to fix CentOS 7 repository.
russjones Dec 17, 2021
fadcdaf
Remove dronegen from Teleport 8.
russjones Dec 17, 2021
eb8f49e
updted Helm install guide in installation page.
flyinghermit Aug 31, 2021
4302e56
Added support for service.spec.loadBalancerIP.
macevil Oct 28, 2021
08e0b0f
Added log configuration to teleport-cluster chart.
webvictim Nov 24, 2021
38f33a0
add TLS routing support to helm chart
Dec 7, 2021
5f9f73b
Restart teleport-kube-agent can't join cluster.
nml11c Dec 11, 2021
3d574ce
Added 12/17 Release Update.
russjones Dec 18, 2021
0ae690a
tool/tsh: support ID for `tsh play -f json`
Dec 8, 2021
b2316bf
Fix initKube: broadcast KubeReady event (#9444)
smallinsky Dec 20, 2021
08c4d66
[helm] Re-add space after type in service definition (#9503)
webvictim Dec 20, 2021
8691555
Updated CHANGELOG.md.
russjones Dec 17, 2021
eb80764
Release 8.0.7.
russjones Dec 17, 2021
7829ce7
Escape access request and access resolution reasons in tctl (#9381) (…
espadolini Dec 21, 2021
00991e6
[v8] Use t.Setenv in tests (#9154) (#9428)
greedy52 Dec 21, 2021
64f8f47
Prevent Linear Retry from converging on Max (#9449)
rosstimothy Dec 21, 2021
a0a3bd1
[v8] Skip tests on a docs-only PR (#9416) (#9510)
tcsc Dec 21, 2021
2cc74f7
Update config.json
russjones Dec 18, 2021
7a9e3f7
Fix tsh db connect mongo dbuser logic (#9445)
smallinsky Dec 22, 2021
3183e61
Fix the UI to correctly determine if a user has access to a resource …
codingllama Dec 22, 2021
eb2649a
Add `--cluster` flag to all `tsh db` subcommands, Add "--diag_addr" f…
greedy52 Dec 22, 2021
280eef6
[v8] Disable drone triggers (#9313) (#9532)
tcsc Dec 23, 2021
77443be
Sign dronefile
tcsc Dec 24, 2021
d5ee160
removes experimental note from example config (#9195) (#9526)
Dec 27, 2021
678747d
Update API client: dial auth service with TLS Routing (#9578)
smallinsky Jan 3, 2022
98a2d83
[branch/v8] update doc examples to change from admin role to editor,a…
stevenGravy Jan 4, 2022
aee8af2
Exclude Jitter from logging
Dec 15, 2021
0cc3e10
Specify level of TLS verification for database connections (#9197) (#…
jakule Jan 6, 2022
cb1d520
(v8) Add note about TLS routing backwards compatibility (#9631)
r0mant Jan 6, 2022
bd9acab
Sign rpm repo metadata (#9623)
wadells Jan 6, 2022
80122c9
[v8]: Desktop Access backports for 8.1.0 (#9678)
zmb3 Jan 7, 2022
e7f44e5
Update previews page (#9670)
r0mant Jan 7, 2022
e364d73
Update e ref
zmb3 Jan 7, 2022
3dc269b
Release 8.1.0 (#9675)
russjones Jan 10, 2022
dd08dc3
[v8] backport #9607 (upgrade `go.etcd.io/etcd`) (#9733)
espadolini Jan 11, 2022
54112b1
Run gpg in batch mode (#9730)
wadells Jan 12, 2022
3ad2939
backport terraform provider syntax changes to v8 (#9541)
programmerq Jan 12, 2022
e3059f6
backport #9656 to branch/v8 (#9746)
rosstimothy Jan 12, 2022
2c1c543
[v8] Restores linting of non-go files in CI (#9664)
tcsc Jan 13, 2022
8f40a7c
fix dynamo error types
fspmarshall Dec 10, 2021
50e79c8
[backport v8] force http2 kubernetes #9294 (#9796)
NajiObeid Jan 18, 2022
0269937
Forward TELEPORT_HOME to kubeconfig (#9760)
atburke Jan 18, 2022
ada04d9
Add info about upcoming databases to previews page (#9832)
r0mant Jan 19, 2022
faacbf5
[Backport V8] Treat EC2 Node IDs as UUIDs (#9833)
nklaassen Jan 19, 2022
1669200
Fall back to "/" when home directory doesn't exist for `tsh ssh` (#94…
atburke Jan 20, 2022
fea1a0a
Add the `access_request.delete` event (#9552) (#9787)
espadolini Jan 20, 2022
be74316
Upload release binaries to new release infrastructure (#8722) (#9615)
justinas Jan 20, 2022
2fef9d8
[docs] Add region and use of SSM decryption to Terraform docs (#8907)…
webvictim Jan 20, 2022
eb95301
fix: removing new line convergance (#9579) (#9816)
webvictim Jan 20, 2022
43efb0b
[auto] Update webassets in branch/v8
espadolini Jan 20, 2022
053249e
Conditionally publish deb packages (#9783)
wadells Jan 21, 2022
16c26ad
Updated CHANGELOG.md.
russjones Jan 21, 2022
851dde0
Release 8.1.1.
russjones Jan 21, 2022
55bc344
[auto] Update webassets in branch/v8 (#9872)
kimlisa Jan 21, 2022
1946553
omit invalid aws tags in rds autodiscovery (#9742) (#9766)
greedy52 Jan 21, 2022
0de35cd
feat: app server requests failover (#9288) (#9819)
gabrielcorado Jan 24, 2022
2b481b9
update RDS and Redshift CA URL (#9890) (#9904)
greedy52 Jan 24, 2022
af7dfd2
Database auto discovery to be more tolerable to find as many as it ca…
greedy52 Jan 24, 2022
bb08c45
Ignore failures for artifact registration step (#9921) (#9927)
justinas Jan 25, 2022
c4a9650
Fix reverse tunnel dialing for Windows Desktops
zmb3 Jan 11, 2022
c0d5350
Clean up system role parsing (#9756)
zmb3 Jan 14, 2022
a5c4eae
docs: recommend a highly available LDAP endpoint. (#9744)
zmb3 Jan 14, 2022
45774dc
Fix first desktop discovery reconcile loop (#9654)
Jan 14, 2022
1f56adc
Reject TDP ClientUsername messages that are too long
zmb3 Jan 20, 2022
991ac88
Add an Error message to TDP (#9586)
Jan 16, 2022
d178a28
Tweak the PNG encoder (#9817)
zmb3 Jan 19, 2022
1cab729
[auto] Update webassets in zmb3/v8-backports (#9906)
Jan 24, 2022
1eccc03
Ignore artifact failures in remaining pipelines (#9932) (#9940)
justinas Jan 25, 2022
5dbe98b
Fix TLS Router serverName 'kube.' prefix based routing logic (#9777) …
smallinsky Jan 26, 2022
c2ca5ed
do not register Aurora serverless db clusters (#9386) (#9934)
greedy52 Jan 26, 2022
db0708b
helm: Add logging configuration to teleport-kube-agent chart (#9632) …
webvictim Jan 26, 2022
50a6bfe
Update upcoming-releases.mdx
russjones Jan 26, 2022
d666b15
[v8] backport #9501 (access requests in TLS certs) (#9922)
espadolini Jan 26, 2022
ef45a7f
tip on cloud and getting ports, added desktop port (#9971)
stevenGravy Jan 26, 2022
8e76cb9
[v8] Auto discovery aurora reader and custom endpoints (#9668) (#9965)
greedy52 Jan 27, 2022
17c3891
Fix k8 access - respect kube service labels (#9759) (#9955)
smallinsky Jan 27, 2022
49367b0
Access request locks (#9478) (#9930)
espadolini Jan 27, 2022
7f62325
backport #9133 to branch/v8 (#9867)
rosstimothy Jan 27, 2022
8fecf57
add extra checks to avoid getSigninToken failure (#9792) (#9964)
greedy52 Jan 27, 2022
ac83ad4
[v8] backport #9697 (improved Google OIDC) (#9926)
espadolini Jan 27, 2022
9316dae
Add access request locks to the docs (#9983)
espadolini Jan 28, 2022
4021abc
[v8] backport #9758 (access requests in audit log) (#9933)
espadolini Jan 28, 2022
570a659
Emit event when connecting to non-Teleport server (#9370)
atburke Jan 28, 2022
04ebfb2
Update golang.org/x/crypto to v0.0.0-20220126234351-aa10faf2a1f8 (#99…
codingllama Jan 28, 2022
ed3e7e9
Make diag-addr in teleport help start unhidden (#9981)
stevenGravy Jan 29, 2022
1778a2e
Vendor go-mysql update
jimbishopp Jan 31, 2022
aa728ef
Client Certificate Authentication for GCP Cloud SQL (#9991)
jimbishopp Jan 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 8 additions & 0 deletions .cloudbuild/ci/doc-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
steps:
- name: quay.io/gravitational/next:main
id: docs-test
env:
- WITH_EXTERNAL_LINKS=true
dir: /src
args: ['yarn', 'remark', '/workspace/docs/pages/**/*.mdx', '--frail']
timeout: 10m
21 changes: 21 additions & 0 deletions .cloudbuild/ci/integration-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
timeout: 25m
options:
machineType: E2_HIGHCPU_32

steps:
# GCB does a shallow checkout for a build, but if we want to check our changes
# against other branches we'll need to fetch the repo history.
- name: gcr.io/cloud-builders/git
id: fetch-history
args: ['fetch', '--unshallow']

# Run the integration tests. Actual content of this job depends on the changes
# detected in the PR
- name: us-docker.pkg.dev/ci-account/teleport/buildbox-root:v0.1.0
id: run-tests
dir: /workspace/.cloudbuild/scripts
entrypoint: bash
args:
- -c
- go run ./cmd/integration-tests -w=/workspace -t=$_BASE_BRANCH -c=HEAD
timeout: 20m
6 changes: 6 additions & 0 deletions .cloudbuild/ci/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
steps:
- name: us-docker.pkg.dev/ci-account/teleport/buildbox-root:v0.1.0
id: lint
args: ['make', 'lint']
options:
machineType: 'E2_HIGHCPU_32'
23 changes: 23 additions & 0 deletions .cloudbuild/ci/unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
timeout: 20m

options:
machineType: 'E2_HIGHCPU_32'

steps:
# GCB does a shallow checkout for a build, but if we want to check our changes
# against other branches we'll need to fetch the repo history. This takes less
# than 30s at the time of writing, so it is probably not worth tweaking.
- name: gcr.io/cloud-builders/git
id: fetch-history
args: ['fetch', '--unshallow']

# Run the unit tests. Actual content of this job depends on the changes
# detected in the PR
- name: us-docker.pkg.dev/ci-account/teleport/buildbox-root:v0.1.0
id: run-tests
dir: /workspace/.cloudbuild/scripts
entrypoint: bash
args:
- -c
- go run ./cmd/unit-tests -w=/workspace -t=$_BASE_BRANCH -c=HEAD
timeout: 15m
194 changes: 194 additions & 0 deletions .cloudbuild/scripts/cmd/integration-tests/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
/*
Copyright 2021 Gravitational, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"context"
"flag"
"fmt"
"io/fs"
"log"
"os"
"os/exec"
"path"
"path/filepath"
"syscall"

"github.com/gravitational/teleport/.cloudbuild/scripts/internal/changes"
"github.com/gravitational/teleport/.cloudbuild/scripts/internal/etcd"
"github.com/gravitational/trace"
)

const (
gomodcacheDir = ".gomodcache-ci"
nonrootUID = 1000
nonrootGID = 1000
)

// main is just a stub that prints out an error message and sets a nonzero exit
// code on failure. All of the work happens in `innerMain()`.
func main() {
if err := innerMain(); err != nil {
log.Fatalf("FAILED: %s", err.Error())
}
}

type commandlineArgs struct {
workspace string
targetBranch string
commitSHA string
skipChown bool
}

func parseCommandLine() (commandlineArgs, error) {
args := commandlineArgs{}

flag.StringVar(&args.workspace, "w", "", "Fully-qualified path to the build workspace")
flag.StringVar(&args.targetBranch, "t", "", "The PR's target branch")
flag.StringVar(&args.commitSHA, "c", "", "The PR's latest commit SHA")
flag.BoolVar(&args.skipChown, "skip-chown", false, "Skip reconfiguring the workspace for a nonroot user.")

flag.Parse()

if args.workspace == "" {
return args, trace.Errorf("workspace path must be set")
}

var err error
args.workspace, err = filepath.Abs(args.workspace)
if err != nil {
return args, trace.Wrap(err, "Unable to resole absolute path to workspace")
}

if args.targetBranch == "" {
return args, trace.Errorf("target branch must be set")
}

if args.commitSHA == "" {
return args, trace.Errorf("commit must be set")
}

return args, nil
}

// innerMain parses the command line, performs the highlevel docs change check
// and creates the marker file if necessary
func innerMain() error {
args, err := parseCommandLine()
if err != nil {
return trace.Wrap(err)
}

gomodcache := fmt.Sprintf("GOMODCACHE=%s", path.Join(args.workspace, gomodcacheDir))

log.Println("Analysing code changes")
ch, err := changes.Analyze(args.workspace, args.targetBranch, args.commitSHA)
if err != nil {
return trace.Wrap(err, "Failed analyzing code")
}

hasOnlyDocChanges := ch.Docs && (!ch.Code)
if hasOnlyDocChanges {
log.Println("No non-docs changes detected. Skipping tests.")
return nil
}

log.Printf("Running root-only integration tests...")
err = runRootIntegrationTests(args.workspace, gomodcache)
if err != nil {
return trace.Wrap(err, "Root-only integration tests failed")
}
log.Println("Root-only integration tests passed.")
if !args.skipChown {
// We run some build steps as root and others as a non user, and we
// want the nonroot user to be able to manipulate the artifacts
// created by root, so we `chown -R` the whole workspace to allow it.
log.Printf("Reconfiguring workspace for nonroot user")
err = chownR(args.workspace, nonrootUID, nonrootGID)
if err != nil {
return trace.Wrap(err, "failed reconfiguring workspace")
}
}

// Note that we run `etcd` as nonroot here. The files created by etcd live
// inside the directory searched by `go list ./...` when generating the list
// of packages to test, and so making them owned by root produces a heap of
// diagnostic warnings that would pollute the build log and just confuse
// people when they are trying to work out why their build failed.
log.Printf("Starting etcd...")
cancelCtx, cancel := context.WithCancel(context.Background())
defer cancel()
err = etcd.Start(cancelCtx, args.workspace, nonrootUID, nonrootGID, gomodcache)
if err != nil {
return trace.Wrap(err, "failed starting etcd")
}

log.Printf("Running nonroot integration tests...")
err = runNonrootIntegrationTests(args.workspace, nonrootUID, nonrootGID, gomodcache)
if err != nil {
return trace.Wrap(err, "Nonroot integration tests failed")
}

log.Printf("Non-root integration tests passed.")

return nil
}

func runRootIntegrationTests(workspace string, env ...string) error {
// Run root integration tests
cmd := exec.Command("make", "rdpclient", "integration-root")
cmd.Dir = workspace
if len(env) > 0 {
cmd.Env = append(os.Environ(), env...)
}
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

return cmd.Run()
}

func runNonrootIntegrationTests(workspace string, uid, gid int, env ...string) error {
cmd := exec.Command("make", "integration")
cmd.Dir = workspace
cmd.Env = append(append(os.Environ(), "TELEPORT_ETCD_TEST=yes"), env...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

// make the command run under the supplied nonroot account
cmd.SysProcAttr = &syscall.SysProcAttr{
Credential: &syscall.Credential{
Uid: uint32(uid),
Gid: uint32(gid),
},
}

return cmd.Run()
}

// chownR changes the owner of each file in the workspace to the supplied
// uid:guid combo.
func chownR(workspace string, uid, gid int) error {
err := filepath.WalkDir(workspace, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}

return os.Chown(path, uid, gid)
})

return trace.Wrap(err, "Failed changing file owner")
}
131 changes: 131 additions & 0 deletions .cloudbuild/scripts/cmd/unit-tests/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
Copyright 2021 Gravitational, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"context"
"flag"
"fmt"
"log"
"os"
"os/exec"
"path"
"path/filepath"

"github.com/gravitational/teleport/.cloudbuild/scripts/internal/changes"
"github.com/gravitational/teleport/.cloudbuild/scripts/internal/etcd"
"github.com/gravitational/trace"
)

const (
gomodcacheDir = ".gomodcache-ci"
)

// main is just a stub that prints out an error message and sets a nonzero exit
// code on failure. All of the work happens in `innerMain()`.
func main() {
if err := innerMain(); err != nil {
log.Fatalf("FAILED: %s", err.Error())
}
}

type commandlineArgs struct {
workspace string
targetBranch string
commitSHA string
}

func parseCommandLine() (commandlineArgs, error) {
args := commandlineArgs{}

flag.StringVar(&args.workspace, "w", "", "Fully-qualified path to the build workspace")
flag.StringVar(&args.targetBranch, "t", "", "The PR's target branch")
flag.StringVar(&args.commitSHA, "c", "", "The PR's latest commit SHA")

flag.Parse()

if args.workspace == "" {
return args, trace.Errorf("workspace path must be set")
}

var err error
args.workspace, err = filepath.Abs(args.workspace)
if err != nil {
return args, trace.Wrap(err, "Unable to resolve absolute path to workspace")
}

if args.targetBranch == "" {
return args, trace.Errorf("target branch must be set")
}

if args.commitSHA == "" {
return args, trace.Errorf("commit must be set")
}

return args, nil
}

// innerMain parses the command line, performs the highlevel docs change check
// and creates the marker file if necessary
func innerMain() error {
args, err := parseCommandLine()
if err != nil {
return trace.Wrap(err)
}

log.Println("Analysing code changes")
ch, err := changes.Analyze(args.workspace, args.targetBranch, args.commitSHA)
if err != nil {
return trace.Wrap(err, "Failed analyzing code")
}

hasOnlyDocChanges := ch.Docs && (!ch.Code)
if hasOnlyDocChanges {
log.Println("No non-docs changes detected. Skipping tests.")
return nil
}

log.Printf("Starting etcd...")
cancelCtx, cancel := context.WithCancel(context.Background())
defer cancel()
err = etcd.Start(cancelCtx, args.workspace, 0, 0)
if err != nil {
return trace.Wrap(err, "failed starting etcd")
}

log.Printf("Running unit tests...")
err = runUnitTests(args.workspace)
if err != nil {
return trace.Wrap(err, "unit tests failed")
}

log.Printf("PASS")

return nil
}

func runUnitTests(workspace string) error {
gomodcache := fmt.Sprintf("GOMODCACHE=%s", path.Join(workspace, gomodcacheDir))

cmd := exec.Command("make", "test")
cmd.Dir = workspace
cmd.Env = append(os.Environ(), gomodcache, "TELEPORT_ETCD_TEST=yes")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

return cmd.Run()
}
Loading