You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailscale/cmd
Alex Chan 139c395d7d cmd/tailscale/cli: stabilise the output of `tailscale lock log --json`
This patch changes the behaviour of `tailscale lock log --json` to make
it more useful for users. It also introduces versioning of our JSON output.

## Changes to `tailscale lock log --json`

Previously this command would print the hash and base64-encoded bytes of
each AUM, and users would need their own CBOR decoder to interpret it in
a useful way:

```json
[
  {
    "Hash": [
      80,
      136,
      151,
      …
    ],
    "Change": "checkpoint",
    "Raw": "pAEFAvYFpQH2AopYIAkPN+8V3cJpkoC5ZY2+RI2Bcg2q5G7tRAQQd67W3YpnWCDPOo4KGeQBd8hdGsjoEQpSXyiPdlm+NXAlJ5dS1qEbFlggylNJDQM5ZQ2ULNsXxg2ZBFkPl/D93I1M56/rowU+UIlYIPZ/SxT9EA2Idy9kaCbsFzjX/s3Ms7584wWGbWd/f/QAWCBHYZzYiAPpQ+NXN+1Wn2fopQYk4yl7kNQcMXUKNAdt1lggcfjcuVACOH0J9pRNvYZQFOkbiBmLOW1hPKJsbC1D1GdYIKrJ38XMgpVMuTuBxM4YwoLmrK/RgXQw1uVEL3cywl3QWCA0FilVVv8uys8BNhS62cfNvCew1Pw5wIgSe3Prv8d8pFggQrwIt6ldYtyFPQcC5V18qrCnt7VpThACaz5RYzpx7RNYIKskOA7UoNiVtMkOrV2QoXv6EvDpbO26a01lVeh8UCeEA4KjAQECAQNYIORIdNHqSOzz1trIygnP5w3JWK2DtlY5NDIBbD7SKcjWowEBAgEDWCD27LpxiZNiA19k0QZhOWmJRvBdK2mz+dHu7rf0iGTPFwQb69Gt42fKNn0FGwRUiav/k6dDF4GiAVgg5Eh00epI7PPW2sjKCc/nDclYrYO2Vjk0MgFsPtIpyNYCWEDzIAooc+m45ay5PB/OB4AA9Fdki4KJq9Ll+PF6IJHYlOVhpTbc3E0KF7ODu1WURd0f7PXnW72dr89CSfGxIHAF"
  }
]
```

Now we print the AUM in an expanded form that can be easily read by scripts,
although we include the raw bytes for verification and auditing.

```json
{
  "SchemaVersion": "1",
  "Messages": [
    {
      "Hash": "KCEJPRKNSXJG2TPH3EHQRLJNLIIK2DV53FUNPADWA7BZJWBDRXZQ",
      "AUM": {
        "MessageKind": "checkpoint",
        "PrevAUMHash": null,
        "Key": null,
        "KeyID": null,
        "State": {
          …
        },
        "Votes": null,
        "Meta": null,
        "Signatures": [
          {
            "KeyID": "tlpub:e44874d1ea48ecf3d6dac8ca09cfe70dc958ad83b656393432016c3ed229c8d6",
            "Signature": "8yAKKHPpuOWsuTwfzgeAAPRXZIuCiavS5fjxeiCR2JTlYaU23NxNChezg7tVlEXdH+z151u9na/PQknxsSBwBQ=="
          }
        ]
      },
      "Raw": "pAEFAvYFpQH2AopYIAkPN-8V3cJpkoC5ZY2-RI2Bcg2q5G7tRAQQd67W3YpnWCDPOo4KGeQBd8hdGsjoEQpSXyiPdlm-NXAlJ5dS1qEbFlggylNJDQM5ZQ2ULNsXxg2ZBFkPl_D93I1M56_rowU-UIlYIPZ_SxT9EA2Idy9kaCbsFzjX_s3Ms7584wWGbWd_f_QAWCBHYZzYiAPpQ-NXN-1Wn2fopQYk4yl7kNQcMXUKNAdt1lggcfjcuVACOH0J9pRNvYZQFOkbiBmLOW1hPKJsbC1D1GdYIKrJ38XMgpVMuTuBxM4YwoLmrK_RgXQw1uVEL3cywl3QWCA0FilVVv8uys8BNhS62cfNvCew1Pw5wIgSe3Prv8d8pFggQrwIt6ldYtyFPQcC5V18qrCnt7VpThACaz5RYzpx7RNYIKskOA7UoNiVtMkOrV2QoXv6EvDpbO26a01lVeh8UCeEA4KjAQECAQNYIORIdNHqSOzz1trIygnP5w3JWK2DtlY5NDIBbD7SKcjWowEBAgEDWCD27LpxiZNiA19k0QZhOWmJRvBdK2mz-dHu7rf0iGTPFwQb69Gt42fKNn0FGwRUiav_k6dDF4GiAVgg5Eh00epI7PPW2sjKCc_nDclYrYO2Vjk0MgFsPtIpyNYCWEDzIAooc-m45ay5PB_OB4AA9Fdki4KJq9Ll-PF6IJHYlOVhpTbc3E0KF7ODu1WURd0f7PXnW72dr89CSfGxIHAF"
    }
  ]
}
```

This output was previously marked as unstable, and it wasn't very useful,
so changing it should be fine.

## Versioning our JSON output

This patch introduces a way to version our JSON output on the CLI, so we
can make backwards-incompatible changes in future without breaking existing
scripts or integrations.

You can run this command in two ways:

```
tailscale lock log --json
tailscale lock log --json=1
```

Passing an explicit version number allows you to pick a specific JSON schema.
If we ever want to change the schema, we increment the version number and
users must opt-in to the new output.

A bare `--json` flag will always return schema version 1, for compatibility
with existing scripts.

Updates https://github.com/tailscale/tailscale/issues/17613
Updates https://github.com/tailscale/corp/issues/23258

Signed-off-by: Alex Chan <alexc@tailscale.com>

Change-Id: I897f78521cc1a81651f5476228c0882d7b723606
2 weeks ago
..
addlicense all: fix golangci-lint errors 11 months ago
build-webclient client/web: precompress assets 2 years ago
checkmetrics cmd/checkmetrics: add command for checking metrics against kb 1 year ago
cloner cmd/cloner: support cloning arbitrarily-nested maps 3 weeks ago
connector-gen cmd/connector-gen: add helper tool for wide app connector configurations 2 years ago
containerboot util/backoff: rename logtail/backoff package to util/backoff 2 months ago
derper util/eventbus: log goroutine stacks when hung in CI 3 weeks ago
derpprobe cmd/derpprobe,prober: add run all probes handler (#16875) 4 months ago
dist {cmd/dist,release/dist}: add support for intermediary QNAP signing certificates 4 months ago
featuretags feature/featuretags,cmd/omitsize: support feature dependencies 3 months ago
get-authkey cmd,tsnet,internal/client: create internal shim to deprecated control plane API 10 months ago
gitops-pusher scripts/check_license_headers.sh: delete, rewrite as a Go test 6 months ago
hello cmd/hello: display native ipv4 (#15191) 9 months ago
jsonimports cmd/jsonimports: add static analyzer for consistent "json" imports (#17669) 1 month ago
k8s-nameserver k8s-operator: add IPv6 support for DNS records (#16691) 2 months ago
k8s-operator ipn/ipnlocal: add PROXY protocol support to Funnel/Serve 2 weeks ago
k8s-proxy cmd/k8s-proxy: switching to using ipn/store/kubestore (#17402) 2 months ago
mkmanifest cmd/mkmanifest, cmd/tailscale, cmd/tailscaled: remove Windows arm32 resources from OSS 3 years ago
mkpkg go.mod: upgrade nfpm to v2 (#8786) 2 years ago
mkversion version/mkversion: open-source version generation logic 3 years ago
nardump cmd/nardump: support symlinks, add basic test 8 months ago
natc cmd/natc,tsconsensus: add cluster config admin 4 months ago
netlogfmt all: use Go 1.22 range-over-int 2 years ago
nginx-auth tailcfg,all: add and use Node.IsTagged() 3 years ago
omitsize feature/featuretags,cmd/omitsize: support feature dependencies 3 months ago
pgproxy all: use new LocalAPI client package location 10 months ago
printdep cmd/printdep: print correct toolchain URL 3 years ago
proxy-test-server net/tlsdial: fix TLS cert validation of HTTPS proxies 6 months ago
proxy-to-grafana scripts/check_license_headers.sh: delete, rewrite as a Go test 6 months ago
sniproxy types/netmap: remove PrivateKey from NetworkMap 2 weeks ago
speedtest all: update copyright and license headers 3 years ago
ssh-auth-none-demo ssh,tempfork/gliderlabs/ssh: replace github.com/tailscale/golang-x-crypto/ssh with golang.org/x/crypto/ssh 10 months ago
stunc cmd/stunc: enforce read timeout deadline (#14309) 1 year ago
stund types/netmap: remove PrivateKey from NetworkMap 2 weeks ago
stunstamp util/backoff: rename logtail/backoff package to util/backoff 2 months ago
sync-containers all: adjust some build tags for plan9 2 years ago
systray client/systray: allow specifying tailscaled socket 4 months ago
tailscale cmd/tailscale/cli: stabilise the output of `tailscale lock log --json` 2 weeks ago
tailscaled ipn/ipnlocal: add PROXY protocol support to Funnel/Serve 2 weeks ago
testcontrol all: use Go 1.22 range-over-int 2 years ago
testwrapper cmd/testwrapper/flakytest: use t.Attr annotation on flaky tests 2 months ago
tl-longchain all: use new LocalAPI client package location 10 months ago
tsconnect net/netmon: remove usage of direct callbacks from netmon (#17292) 2 months ago
tsidp ipn/ipnlocal: add PROXY protocol support to Funnel/Serve 2 weeks ago
tsshd all: update copyright and license headers 3 years ago
tta all: use new LocalAPI client package location 10 months ago
vet cmd/vet: add static vet checker that runs jsontags (#17778) 4 weeks ago
viewer cmd/{cloner,viewer}: handle maps of views 3 weeks ago
vnet cmd/vnet: add wsproxy mode 8 months ago
xdpderper tsweb: split promvarz into an optional dependency 9 months ago