@@ -10,7 +10,6 @@ import (
10
10
"crypto/tls"
11
11
"crypto/x509"
12
12
"database/sql"
13
- "encoding/hex"
14
13
"errors"
15
14
"flag"
16
15
"fmt"
@@ -62,6 +61,7 @@ import (
62
61
"github.com/coder/serpent"
63
62
"github.com/coder/wgtunnel/tunnelsdk"
64
63
64
+ "github.com/coder/coder/v2/coderd/cryptokeys"
65
65
"github.com/coder/coder/v2/coderd/entitlements"
66
66
"github.com/coder/coder/v2/coderd/notifications/reports"
67
67
"github.com/coder/coder/v2/coderd/runtimeconfig"
@@ -97,7 +97,6 @@ import (
97
97
"github.com/coder/coder/v2/coderd/updatecheck"
98
98
"github.com/coder/coder/v2/coderd/util/slice"
99
99
stringutil "github.com/coder/coder/v2/coderd/util/strings"
100
- "github.com/coder/coder/v2/coderd/workspaceapps"
101
100
"github.com/coder/coder/v2/coderd/workspaceapps/appurl"
102
101
"github.com/coder/coder/v2/coderd/workspacestats"
103
102
"github.com/coder/coder/v2/codersdk"
@@ -741,90 +740,19 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
741
740
return xerrors .Errorf ("set deployment id: %w" , err )
742
741
}
743
742
}
744
-
745
- // Read the app signing key from the DB. We store it hex encoded
746
- // since the config table uses strings for the value and we
747
- // don't want to deal with automatic encoding issues.
748
- appSecurityKeyStr , err := tx .GetAppSecurityKey (ctx )
749
- if err != nil && ! xerrors .Is (err , sql .ErrNoRows ) {
750
- return xerrors .Errorf ("get app signing key: %w" , err )
751
- }
752
- // If the string in the DB is an invalid hex string or the
753
- // length is not equal to the current key length, generate a new
754
- // one.
755
- //
756
- // If the key is regenerated, old signed tokens and encrypted
757
- // strings will become invalid. New signed app tokens will be
758
- // generated automatically on failure. Any workspace app token
759
- // smuggling operations in progress may fail, although with a
760
- // helpful error.
761
- if decoded , err := hex .DecodeString (appSecurityKeyStr ); err != nil || len (decoded ) != len (workspaceapps.SecurityKey {}) {
762
- b := make ([]byte , len (workspaceapps.SecurityKey {}))
763
- _ , err := rand .Read (b )
764
- if err != nil {
765
- return xerrors .Errorf ("generate fresh app signing key: %w" , err )
766
- }
767
-
768
- appSecurityKeyStr = hex .EncodeToString (b )
769
- err = tx .UpsertAppSecurityKey (ctx , appSecurityKeyStr )
770
- if err != nil {
771
- return xerrors .Errorf ("insert freshly generated app signing key to database: %w" , err )
772
- }
773
- }
774
-
775
- appSecurityKey , err := workspaceapps .KeyFromString (appSecurityKeyStr )
776
- if err != nil {
777
- return xerrors .Errorf ("decode app signing key from database: %w" , err )
778
- }
779
-
780
- options .AppSecurityKey = appSecurityKey
781
-
782
- // Read the oauth signing key from the database. Like the app security, generate a new one
783
- // if it is invalid for any reason.
784
- oauthSigningKeyStr , err := tx .GetOAuthSigningKey (ctx )
785
- if err != nil && ! xerrors .Is (err , sql .ErrNoRows ) {
786
- return xerrors .Errorf ("get app oauth signing key: %w" , err )
787
- }
788
- if decoded , err := hex .DecodeString (oauthSigningKeyStr ); err != nil || len (decoded ) != len (options .OAuthSigningKey ) {
789
- b := make ([]byte , len (options .OAuthSigningKey ))
790
- _ , err := rand .Read (b )
791
- if err != nil {
792
- return xerrors .Errorf ("generate fresh oauth signing key: %w" , err )
793
- }
794
-
795
- oauthSigningKeyStr = hex .EncodeToString (b )
796
- err = tx .UpsertOAuthSigningKey (ctx , oauthSigningKeyStr )
797
- if err != nil {
798
- return xerrors .Errorf ("insert freshly generated oauth signing key to database: %w" , err )
799
- }
800
- }
801
-
802
- oauthKeyBytes , err := hex .DecodeString (oauthSigningKeyStr )
803
- if err != nil {
804
- return xerrors .Errorf ("decode oauth signing key from database: %w" , err )
805
- }
806
- if len (oauthKeyBytes ) != len (options .OAuthSigningKey ) {
807
- return xerrors .Errorf ("oauth signing key in database is not the correct length, expect %d got %d" , len (options .OAuthSigningKey ), len (oauthKeyBytes ))
808
- }
809
- copy (options .OAuthSigningKey [:], oauthKeyBytes )
810
- if options .OAuthSigningKey == [32 ]byte {} {
811
- return xerrors .Errorf ("oauth signing key in database is empty" )
812
- }
813
-
814
- // Read the coordinator resume token signing key from the
815
- // database.
816
- resumeTokenKey , err := tailnet .ResumeTokenSigningKeyFromDatabase (ctx , tx )
817
- if err != nil {
818
- return xerrors .Errorf ("get coordinator resume token key from database: %w" , err )
819
- }
820
- options .CoordinatorResumeTokenProvider = tailnet .NewResumeTokenKeyProvider (resumeTokenKey , quartz .NewReal (), tailnet .DefaultResumeTokenExpiry )
821
-
822
743
return nil
823
744
}, nil )
824
745
if err != nil {
825
- return err
746
+ return xerrors . Errorf ( "set deployment id: %w" , err )
826
747
}
827
748
749
+ resumeKeycache , err := cryptokeys .NewSigningCache (logger , options .Database , database .CryptoKeyFeatureTailnetResume )
750
+ if err != nil {
751
+ return xerrors .Errorf ("create resume token key cache: %w" , err )
752
+ }
753
+
754
+ options .CoordinatorResumeTokenProvider = tailnet .NewResumeTokenKeyProvider (resumeKeycache , quartz .NewReal (), tailnet .DefaultResumeTokenExpiry )
755
+
828
756
options .RuntimeConfig = runtimeconfig .NewManager ()
829
757
830
758
// This should be output before the logs start streaming.
0 commit comments