diff --git a/go.mod b/go.mod index 3e34dcc..6b08e77 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.27 require ( code.gitea.io/sdk/gitea v0.25.1 + filippo.io/age v1.3.2 github.com/emersion/go-imap/v2 v2.0.0-beta.8 github.com/emersion/go-message v0.18.2 github.com/emersion/go-msgauth v0.7.0 @@ -12,26 +13,43 @@ require ( github.com/gofri/go-github-ratelimit/v2 v2.0.2 github.com/google/go-github/v78 v78.0.0 github.com/hashicorp/go-plugin v1.8.0 + github.com/hashicorp/vault/api v1.23.0 google.golang.org/grpc v1.84.0 google.golang.org/protobuf v1.36.12 ) require ( + filippo.io/hpke v0.4.0 // indirect github.com/42wim/httpsig v1.2.4 // indirect + github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/davidmz/go-pageant v1.0.2 // indirect - github.com/fatih/color v1.13.0 // indirect + github.com/fatih/color v1.18.0 // indirect github.com/go-fed/httpsig v1.1.0 // indirect + github.com/go-jose/go-jose/v4 v4.1.4 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/google/go-querystring v1.1.0 // indirect + github.com/hashicorp/errwrap v1.1.0 // indirect + github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-hclog v1.6.3 // indirect + github.com/hashicorp/go-multierror v1.1.1 // indirect + github.com/hashicorp/go-retryablehttp v0.7.8 // indirect + github.com/hashicorp/go-rootcerts v1.0.2 // indirect + github.com/hashicorp/go-secure-stdlib/parseutil v0.2.0 // indirect + github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect + github.com/hashicorp/go-sockaddr v1.0.7 // indirect github.com/hashicorp/go-version v1.9.0 // indirect + github.com/hashicorp/hcl v1.0.1-vault-7 // indirect github.com/hashicorp/yamux v0.1.2 // indirect - github.com/mattn/go-colorable v0.1.12 // indirect - github.com/mattn/go-isatty v0.0.17 // indirect + github.com/mattn/go-colorable v0.1.14 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mitchellh/go-homedir v1.1.0 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/oklog/run v1.1.0 // indirect - golang.org/x/crypto v0.54.0 // indirect + github.com/ryanuber/go-glob v1.0.0 // indirect + golang.org/x/crypto v0.55.0 // indirect golang.org/x/net v0.57.0 // indirect golang.org/x/sys v0.47.0 // indirect - golang.org/x/text v0.40.0 // indirect + golang.org/x/text v0.41.0 // indirect + golang.org/x/time v0.12.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20260706201446-f0a921348800 // indirect ) diff --git a/go.sum b/go.sum index 295c8cc..1fd751e 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,17 @@ +c2sp.org/CCTV/age v0.0.0-20260829155415-4448f2097b2d h1:Blprhc2SbChNZtWcU+BLTM4YdoqYAS9V7cJgOwJKyAs= +c2sp.org/CCTV/age v0.0.0-20260829155415-4448f2097b2d/go.mod h1:SrHC2C7r5GkDk8R+NFVzYy/sdj0Ypg9htaPXQq5Cqeo= code.gitea.io/sdk/gitea v0.25.1 h1:yywxWwoV+SdjHtbC6unBiXojWdZOtoHuGhEazEXeWuE= code.gitea.io/sdk/gitea v0.25.1/go.mod h1:uDFWYBU8dgZsgOHwe6C/6olxvf8FHguNB3wW1i83fgg= +filippo.io/age v1.3.2 h1:r6RSZLFSMm6rzKepZ7ZAYkKCu14f3/Me8c7uKYh7C8c= +filippo.io/age v1.3.2/go.mod h1:TH/Yr2sSRhCKbaH4XPxpUV0Us8Gv6txYUpiZQWz8Evk= +filippo.io/hpke v0.4.0 h1:p575VVQ6ted4pL+it6M00V/f2qTZITO0zgmdKCkd5+A= +filippo.io/hpke v0.4.0/go.mod h1:EmAN849/P3qdeK+PCMkDpDm83vRHM5cDipBJ8xbQLVY= github.com/42wim/httpsig v1.2.4 h1:mI5bH0nm4xn7K18fo1K3okNDRq8CCJ0KbBYWyA6r8lU= github.com/42wim/httpsig v1.2.4/go.mod h1:yKsYfSyTBEohkPik224QPFylmzEBtda/kjyIAJjh3ps= github.com/bufbuild/protocompile v0.14.1 h1:iA73zAf/fyljNjQKwYzUHD6AD4R8KMasmwa/FBatYVw= github.com/bufbuild/protocompile v0.14.1/go.mod h1:ppVdAIhbr2H8asPk6k4pY7t9zB1OU5DoEw9xY/FUi1c= +github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= +github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -19,10 +27,15 @@ github.com/emersion/go-sasl v0.0.0-20241020182733-b788ff22d5a6 h1:oP4q0fw+fOSWn3 github.com/emersion/go-sasl v0.0.0-20241020182733-b788ff22d5a6/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ= github.com/emersion/go-smtp v0.25.0 h1:krfiHrme2JbJYDh0DGuSRbvPpbnQTH/v9CIfPincl1I= github.com/emersion/go-smtp v0.25.0/go.mod h1:ZtRRkbTyp2XTHCA+BmyTFTrj8xY4I+b4McvHxCU2gsQ= -github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= +github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM= +github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU= github.com/go-fed/httpsig v1.1.0 h1:9M+hb0jkEICD8/cAiNqEB66R87tTINszBRTjwjQzWcI= github.com/go-fed/httpsig v1.1.0/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM= +github.com/go-jose/go-jose/v4 v4.1.4 h1:moDMcTHmvE6Groj34emNPLs/qtYXRVcd6S7NHbHz3kA= +github.com/go-jose/go-jose/v4 v4.1.4/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08= +github.com/go-test/deep v1.1.1 h1:0r/53hagsehfO4bzD2Pgr/+RgHqhmf+k1Bpse2cTu1U= +github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= github.com/gofri/go-github-ratelimit/v2 v2.0.2 h1:gS8wAS1jTmlWGdTjAM7KIpsLjwY1S0S/gKK5hthfSXM= github.com/gofri/go-github-ratelimit/v2 v2.0.2/go.mod h1:YBQt4gTbdcbMjJFT05YFEaECwH78P5b0IwrnbLiHGdE= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= @@ -34,27 +47,55 @@ github.com/google/go-github/v78 v78.0.0 h1:b1tytzFE8i//lRVDx5Qh/EdJbtTPtSVD3nF7h github.com/google/go-github/v78 v78.0.0/go.mod h1:Uxvdzy82AkNlC6JQ57se9TqvmgBT7RF0ouHDNg2jd6g= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= +github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= +github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= +github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/go-plugin v1.8.0 h1:ie8S6RRY8RvB2usYZv+AAZ/wBvx2AU5p5QeP5j/FORs= github.com/hashicorp/go-plugin v1.8.0/go.mod h1:BExt6KEaIYx804z8k4gRzRLEvxKVb+kn0NMcihqOqb8= +github.com/hashicorp/go-retryablehttp v0.7.8 h1:ylXZWnqa7Lhqpk0L1P1LzDtGcCR0rPVUrx/c8Unxc48= +github.com/hashicorp/go-retryablehttp v0.7.8/go.mod h1:rjiScheydd+CxvumBsIrFKlx3iS0jrZ7LvzFGFmuKbw= +github.com/hashicorp/go-rootcerts v1.0.2 h1:jzhAVGtqPKbwpyCPELlgNWhE1znq+qwJtW5Oi2viEzc= +github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= +github.com/hashicorp/go-secure-stdlib/parseutil v0.2.0 h1:U+kC2dOhMFQctRfhK0gRctKAPTloZdMU5ZJxaesJ/VM= +github.com/hashicorp/go-secure-stdlib/parseutil v0.2.0/go.mod h1:Ll013mhdmsVDuoIXVfBtvgGJsXDYkTw1kooNcoCXuE0= +github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 h1:kes8mmyCpxJsI7FTwtzRqEy9CdjCtrXrXGuOpxEA7Ts= +github.com/hashicorp/go-secure-stdlib/strutil v0.1.2/go.mod h1:Gou2R9+il93BqX25LAKCLuM+y9U2T4hlwvT1yprcna4= +github.com/hashicorp/go-sockaddr v1.0.7 h1:G+pTkSO01HpR5qCxg7lxfsFEZaG+C0VssTy/9dbT+Fw= +github.com/hashicorp/go-sockaddr v1.0.7/go.mod h1:FZQbEYa1pxkQ7WLpyXJ6cbjpT8q0YgQaK/JakXqGyWw= github.com/hashicorp/go-version v1.9.0 h1:CeOIz6k+LoN3qX9Z0tyQrPtiB1DFYRPfCIBtaXPSCnA= github.com/hashicorp/go-version v1.9.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/hcl v1.0.1-vault-7 h1:ag5OxFVy3QYTFTJODRzTKVZ6xvdfLLCA1cy/Y6xGI0I= +github.com/hashicorp/hcl v1.0.1-vault-7/go.mod h1:XYhtn6ijBSAj6n4YqAaf7RBPS4I06AItNorpy+MoQNM= +github.com/hashicorp/vault/api v1.23.0 h1:gXgluBsSECfRWTSW9niY2jwg2e9mMJc4WoHNv4g3h6A= +github.com/hashicorp/vault/api v1.23.0/go.mod h1:zransKiB9ftp+kgY8ydjnvCU7Wk8i9L0DYWpXeMj9ko= github.com/hashicorp/yamux v0.1.2 h1:XtB8kyFOyHXYVFnwT5C3+Bdo8gArse7j2AQ0DA0Uey8= github.com/hashicorp/yamux v0.1.2/go.mod h1:C+zze2n6e/7wshOZep2A70/aQU6QBRWJO/G6FT1wIns= github.com/jhump/protoreflect v1.17.0 h1:qOEr613fac2lOuTgWN4tPAtLL7fUSbuJL5X5XumQh94= github.com/jhump/protoreflect v1.17.0/go.mod h1:h9+vUUL38jiBzck8ck+6G/aeMX8Z4QUY/NiJPwPNi+8= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= +github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= -github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk= +github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= @@ -64,8 +105,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.54.0 h1:YLIA59K4fiNzHzjnZt2tUJQjQtUWfWbeHBqKtk3eScw= -golang.org/x/crypto v0.54.0/go.mod h1:KWL8ny2AZdGR2cWmzeHrp2azQPGogOv+HeQaVEXC2dk= +golang.org/x/crypto v0.55.0 h1:+KWHjbgOaAQ66dh/YlkZKHlz9ZUlq61AFirAR9ntP8M= +golang.org/x/crypto v0.55.0/go.mod h1:uq0V9dE/fzQuJtbnL+2EhWOE63vo164FY8xqEnV9xis= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -89,8 +130,8 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs= golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -103,8 +144,10 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/text v0.40.0 h1:Ub2Z6/xjgF1WrYQz2nuITOEegKFtiIy+rieRJ5lHZKs= -golang.org/x/text v0.40.0/go.mod h1:hpnzDAfGV753zIKo+wk3u1bVKCGPbrnF7+7LBF/UHVY= +golang.org/x/text v0.41.0 h1:vz/seA0lnX87Othu2f/0L24RcgrXD9/YFTSuGjj3rH8= +golang.org/x/text v0.41.0/go.mod h1:jvf1O8ajNzZqhSrQBPbutR/EB83Cc0CFrezNQIwbb5M= +golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE= +golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= diff --git a/secret-engines/age/main.go b/secret-engines/age/main.go index 42e9a76..4f6f6bf 100644 --- a/secret-engines/age/main.go +++ b/secret-engines/age/main.go @@ -1,29 +1,63 @@ // age resolves a key from an age-encrypted file of "key=value" lines. It needs -// the age CLI on PATH, AGE_FILE (the encrypted file) and AGE_IDENTITY (the age -// private-key file). Blank lines and "#" comments are skipped, a value may -// contain "=", and an empty value counts as missing. +// AGE_FILE (the encrypted file) and AGE_IDENTITY (the age private-key file). +// Blank lines and "#" comments are skipped, a value may contain "=", and an +// empty value counts as missing. package main import ( + "bytes" "context" "errors" "fmt" + "io" "os" "strings" + "filippo.io/age" + "github.com/samcharles93/archipelago/sdk/secretengine" ) -func resolve(ctx context.Context, key string) (string, error) { +func resolve(_ context.Context, key string) (string, error) { file, identity := os.Getenv("AGE_FILE"), os.Getenv("AGE_IDENTITY") if file == "" || identity == "" { return "", errors.New("AGE_FILE and AGE_IDENTITY must be set") } - out, err := secretengine.Run(ctx, "age", "-d", "-i", identity, file) + plain, err := decrypt(file, identity) if err != nil { - return "", fmt.Errorf("decrypt %s: %w", file, err) + return "", err } - for _, line := range strings.Split(out, "\n") { + return lookup(plain, key) +} + +func decrypt(file, identityFile string) ([]byte, error) { + keys, err := os.ReadFile(identityFile) + if err != nil { + return nil, fmt.Errorf("read identity: %w", err) + } + identities, err := age.ParseIdentities(bytes.NewReader(keys)) + if err != nil { + return nil, fmt.Errorf("parse identity %s: %w", identityFile, err) + } + f, err := os.Open(file) + if err != nil { + return nil, fmt.Errorf("open %s: %w", file, err) + } + defer func() { _ = f.Close() }() + r, err := age.Decrypt(f, identities...) + if err != nil { + return nil, fmt.Errorf("decrypt %s: %w", file, err) + } + plain, err := io.ReadAll(r) + if err != nil { + return nil, fmt.Errorf("decrypt %s: %w", file, err) + } + return plain, nil +} + +// lookup finds key in "key=value" lines. +func lookup(plain []byte, key string) (string, error) { + for line := range strings.SplitSeq(string(plain), "\n") { line = strings.TrimSpace(line) name, value, ok := strings.Cut(line, "=") if line == "" || strings.HasPrefix(line, "#") || !ok || strings.TrimSpace(name) != key { diff --git a/secret-engines/age/main_test.go b/secret-engines/age/main_test.go new file mode 100644 index 0000000..97f3922 --- /dev/null +++ b/secret-engines/age/main_test.go @@ -0,0 +1,57 @@ +package main + +import ( + "bytes" + "errors" + "os" + "path/filepath" + "testing" + + "filippo.io/age" + + "github.com/samcharles93/archipelago/sdk/secretengine" +) + +func TestResolve(t *testing.T) { + identity, err := age.GenerateX25519Identity() + if err != nil { + t.Fatal(err) + } + dir := t.TempDir() + var sealed bytes.Buffer + w, err := age.Encrypt(&sealed, identity.Recipient()) + if err != nil { + t.Fatal(err) + } + _, _ = w.Write([]byte("# tokens\ntoken = a=b\nempty=\n")) + _ = w.Close() + write := func(name string, data []byte) string { + p := filepath.Join(dir, name) + if err := os.WriteFile(p, data, 0o600); err != nil { + t.Fatal(err) + } + return p + } + t.Setenv("AGE_FILE", write("secrets.age", sealed.Bytes())) + t.Setenv("AGE_IDENTITY", write("key.txt", []byte(identity.String()+"\n"))) + + for _, tc := range []struct { + key, want string + missing bool + }{ + {key: "token", want: "a=b"}, + {key: "empty", missing: true}, + {key: "absent", missing: true}, + } { + got, err := resolve(t.Context(), tc.key) + if tc.missing != errors.Is(err, secretengine.ErrNotFound) || got != tc.want { + t.Errorf("resolve(%q) = %q, %v", tc.key, got, err) + } + } + + other, _ := age.GenerateX25519Identity() + t.Setenv("AGE_IDENTITY", write("other.txt", []byte(other.String()+"\n"))) + if _, err := resolve(t.Context(), "token"); err == nil || errors.Is(err, secretengine.ErrNotFound) { + t.Fatalf("wrong identity: err = %v, want a decrypt failure, not a missing key", err) + } +} diff --git a/secret-engines/age/package.yaml b/secret-engines/age/package.yaml index 9c5a206..f16e625 100644 --- a/secret-engines/age/package.yaml +++ b/secret-engines/age/package.yaml @@ -1,7 +1,7 @@ apiVersion: dev.archie.package.v1 displayName: age -description: Resolve secret references from an age-encrypted key=value file through the age CLI. -version: 1.0.0 +description: Resolve secret references from an age-encrypted key=value file. +version: 1.1.0 contributes: extensions: - surface: secretengine diff --git a/secret-engines/sops/main.go b/secret-engines/sops/main.go index 849e667..a68e208 100644 --- a/secret-engines/sops/main.go +++ b/secret-engines/sops/main.go @@ -1,13 +1,13 @@ -// sops resolves a top-level key from a sops-encrypted file. It needs the sops -// CLI on PATH and SOPS_FILE (the encrypted file). +// sops resolves a top-level key from a sops-encrypted file (YAML, JSON, dotenv +// or INI). It needs the sops CLI on PATH and SOPS_FILE (the encrypted file). package main import ( "context" + "encoding/json" "errors" "fmt" "os" - "strings" "github.com/samcharles93/archipelago/sdk/secretengine" ) @@ -17,17 +17,35 @@ func resolve(ctx context.Context, key string) (string, error) { if file == "" { return "", errors.New("SOPS_FILE is not set") } - if strings.ContainsAny(key, `"\[`) { - return "", fmt.Errorf("key %q is not a valid --extract path", key) - } - value, err := secretengine.Run(ctx, "sops", "-d", "--extract", `["`+key+`"]`, file) + // The whole file decrypts to JSON and the key is looked up here, so a + // missing key reads as missing rather than as a failed decrypt, and the + // key never reaches the CLI. + plain, err := secretengine.Run(ctx, "sops", "--decrypt", "--output-type", "json", file) if err != nil { return "", fmt.Errorf("decrypt %s: %w", file, err) } - if value == "" { + return lookup([]byte(plain), key) +} + +// lookup returns a top-level key's value: a string as written, anything else +// as JSON. +func lookup(plain []byte, key string) (string, error) { + var doc map[string]json.RawMessage + if err := json.Unmarshal(plain, &doc); err != nil { + return "", fmt.Errorf("decode decrypted file: %w", err) + } + raw, ok := doc[key] + if !ok || string(raw) == "null" { return "", secretengine.ErrNotFound } - return value, nil + var s string + if json.Unmarshal(raw, &s) == nil { + if s == "" { + return "", secretengine.ErrNotFound + } + return s, nil + } + return string(raw), nil } func main() { secretengine.ServeFunc(resolve) } diff --git a/secret-engines/sops/main_test.go b/secret-engines/sops/main_test.go new file mode 100644 index 0000000..baa75f2 --- /dev/null +++ b/secret-engines/sops/main_test.go @@ -0,0 +1,28 @@ +package main + +import ( + "errors" + "testing" + + "github.com/samcharles93/archipelago/sdk/secretengine" +) + +func TestLookup(t *testing.T) { + plain := []byte(`{"token":"s3cret","port":5432,"nested":{"a":1},"empty":"","nil":null}`) + for _, tc := range []struct { + key, want string + missing bool + }{ + {key: "token", want: "s3cret"}, + {key: "port", want: "5432"}, + {key: "nested", want: `{"a":1}`}, + {key: "empty", missing: true}, + {key: "nil", missing: true}, + {key: `"] --output x`, missing: true}, + } { + got, err := lookup(plain, tc.key) + if tc.missing != errors.Is(err, secretengine.ErrNotFound) || got != tc.want { + t.Errorf("lookup(%q) = %q, %v", tc.key, got, err) + } + } +} diff --git a/secret-engines/sops/package.yaml b/secret-engines/sops/package.yaml index 4c8010c..74eaa0b 100644 --- a/secret-engines/sops/package.yaml +++ b/secret-engines/sops/package.yaml @@ -1,7 +1,7 @@ apiVersion: dev.archie.package.v1 displayName: SOPS description: Resolve secret references from a sops-encrypted file through the sops CLI. -version: 1.0.0 +version: 1.1.0 contributes: extensions: - surface: secretengine diff --git a/secret-engines/vault/main.go b/secret-engines/vault/main.go index 005c950..ff6a883 100644 --- a/secret-engines/vault/main.go +++ b/secret-engines/vault/main.go @@ -1,6 +1,7 @@ -// vault resolves a field of a KV secret through the vault CLI (also works with -// OpenBao). It needs VAULT_ADDR and VAULT_TOKEN. A key is "path/field"; a key -// with no slash is a field under VAULT_SECRET_PATH. +// vault resolves a field of a KV secret over the Vault API (also works with +// OpenBao), on KV version 1 or 2 mounts alike. It needs VAULT_ADDR and +// VAULT_TOKEN. A key is "path/field"; a key with no slash is a field under +// VAULT_SECRET_PATH. package main import ( @@ -10,6 +11,8 @@ import ( "os" "strings" + vault "github.com/hashicorp/vault/api" + "github.com/samcharles93/archipelago/sdk/secretengine" ) @@ -21,26 +24,77 @@ func resolve(ctx context.Context, key string) (string, error) { if err != nil { return "", err } - - value, err := secretengine.Run(ctx, "vault", "kv", "get", "-field="+field, path) + client, err := vault.NewClient(vault.DefaultConfig()) if err != nil { - return "", fmt.Errorf("read %s/%s: %w", path, field, err) + return "", fmt.Errorf("vault client: %w", err) } - if value == "" { + data, err := read(ctx, client.Logical(), path) + if err != nil { + return "", err + } + value, ok := data[field].(string) + if !ok || value == "" { return "", secretengine.ErrNotFound } return value, nil } -// target splits key into the CLI's path and field. Both reach the vault CLI as -// arguments, so a path with a leading "-" is refused: it would be read as a -// flag such as -address. +// read returns a KV secret's fields, finding the mount and its KV version the +// way the vault CLI does. A secret that does not exist is ErrNotFound. +func read(ctx context.Context, logical *vault.Logical, path string) (map[string]any, error) { + mount, version, err := kvMount(ctx, logical, path) + if err != nil { + return nil, err + } + readPath := path + if version == "2" { + readPath = mount + "data/" + strings.TrimPrefix(path, mount) + } + secret, err := logical.ReadWithContext(ctx, readPath) + if err != nil { + return nil, fmt.Errorf("read %s: %w", path, err) + } + if secret == nil || secret.Data == nil { + return nil, secretengine.ErrNotFound + } + if version != "2" { + return secret.Data, nil + } + data, _ := secret.Data["data"].(map[string]any) + if data == nil { + return nil, secretengine.ErrNotFound // deleted or destroyed version + } + return data, nil +} + +// kvMount returns the mount path (with its trailing slash) holding path and +// its KV version, "1" or "2". +func kvMount(ctx context.Context, logical *vault.Logical, path string) (string, string, error) { + secret, err := logical.ReadWithContext(ctx, "sys/internal/ui/mounts/"+path) + if err != nil { + return "", "", fmt.Errorf("find the mount for %s: %w", path, err) + } + if secret == nil || secret.Data == nil { + return "", "", fmt.Errorf("find the mount for %s: no mount holds it", path) + } + mount, _ := secret.Data["path"].(string) + version := "1" + if options, ok := secret.Data["options"].(map[string]any); ok { + if v, ok := options["version"].(string); ok && v != "" { + version = v + } + } + return mount, version, nil +} + +// target splits key into a secret path and field. A path with a leading "-" +// or a ".." segment is refused: neither names a KV secret. func target(key string) (path, field string, err error) { path, field = os.Getenv("VAULT_SECRET_PATH"), key if i := strings.LastIndex(key, "/"); i >= 0 { path, field = key[:i], key[i+1:] } - if path == "" || field == "" || strings.HasPrefix(path, "-") { + if path == "" || field == "" || strings.HasPrefix(path, "-") || strings.Contains("/"+path+"/", "/../") { return "", "", fmt.Errorf("key %q is not a valid path/field (a key with no path needs VAULT_SECRET_PATH)", key) } return path, field, nil diff --git a/secret-engines/vault/main_test.go b/secret-engines/vault/main_test.go index 0ac9d65..9acae55 100644 --- a/secret-engines/vault/main_test.go +++ b/secret-engines/vault/main_test.go @@ -1,6 +1,13 @@ package main -import "testing" +import ( + "errors" + "net/http" + "net/http/httptest" + "testing" + + "github.com/samcharles93/archipelago/sdk/secretengine" +) func TestTarget(t *testing.T) { t.Setenv("VAULT_SECRET_PATH", "") @@ -10,6 +17,7 @@ func TestTarget(t *testing.T) { }{ {"secret/app/token", "secret/app", "token", true}, {"-address=http://evil/x", "", "", false}, + {"secret/../sys/token", "", "", false}, {"secret/app/", "", "", false}, {"token", "", "", false}, } { @@ -19,3 +27,43 @@ func TestTarget(t *testing.T) { } } } + +// A missing secret or field is not found, on either KV version; the CLI this +// replaced reported both as the engine being unavailable. +func TestResolve(t *testing.T) { + mounts := map[string]string{ + "/v1/sys/internal/ui/mounts/kv2/app": `{"data":{"path":"kv2/","options":{"version":"2"}}}`, + "/v1/sys/internal/ui/mounts/kv1/app": `{"data":{"path":"kv1/","options":null}}`, + "/v1/sys/internal/ui/mounts/kv2/gone": `{"data":{"path":"kv2/","options":{"version":"2"}}}`, + } + secrets := map[string]string{"/v1/kv2/data/app": `{"data":{"data":{"token":"v2"}}}`, "/v1/kv1/app": `{"data":{"token":"v1"}}`} + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if body, ok := mounts[r.URL.Path]; ok { + _, _ = w.Write([]byte(body)) + return + } + if body, ok := secrets[r.URL.Path]; ok { + _, _ = w.Write([]byte(body)) + return + } + w.WriteHeader(http.StatusNotFound) + _, _ = w.Write([]byte(`{"errors":[]}`)) + })) + defer srv.Close() + t.Setenv("VAULT_ADDR", srv.URL) + t.Setenv("VAULT_TOKEN", "t") + for _, tc := range []struct { + key, want string + missing bool + }{ + {key: "kv2/app/token", want: "v2"}, + {key: "kv1/app/token", want: "v1"}, + {key: "kv2/app/absent", missing: true}, + {key: "kv2/gone/token", missing: true}, + } { + got, err := resolve(t.Context(), tc.key) + if tc.missing != errors.Is(err, secretengine.ErrNotFound) || got != tc.want { + t.Errorf("resolve(%q) = %q, %v", tc.key, got, err) + } + } +} diff --git a/secret-engines/vault/package.yaml b/secret-engines/vault/package.yaml index 2a9238e..f64f916 100644 --- a/secret-engines/vault/package.yaml +++ b/secret-engines/vault/package.yaml @@ -1,7 +1,7 @@ apiVersion: dev.archie.package.v1 displayName: Vault / OpenBao -description: Resolve secret references from a KV secret through the vault CLI. -version: 1.0.0 +description: Resolve secret references from a KV secret over the Vault or OpenBao API. +version: 1.1.0 contributes: extensions: - surface: secretengine