@@ -118,6 +118,47 @@ func isAlreadyInstalled() (bool, error) {
118118 }
119119}
120120
121+ func checkLicenseMatches (c * cli.Context ) error {
122+ rel , err := release .GetChannelRelease ()
123+ if err != nil {
124+ return fmt .Errorf ("failed to get release from binary: %w" , err ) // this should only be if the release is malformed
125+ }
126+
127+ // handle the three cases that do not require parsing the license file
128+ // 1. no release and no license, which is OK
129+ // 2. no license and a release, which is not OK
130+ // 3. a license and no release, which is not OK
131+ if rel == nil && c .String ("license" ) == "" {
132+ // no license and no release, this is OK
133+ return nil
134+ } else if rel == nil && c .String ("license" ) != "" {
135+ // license is present but no release, this means we would install without vendor charts and k0s overrides
136+ return fmt .Errorf ("a license was provided but no release was found in binary" )
137+ } else if rel != nil && c .String ("license" ) == "" {
138+ // release is present but no license, this is not OK
139+ return fmt .Errorf ("no license was provided for %s" , rel .AppSlug )
140+ }
141+
142+ license , err := helpers .ParseLicense (c .String ("license" ))
143+ if err != nil {
144+ return fmt .Errorf ("unable to parse license: %w" , err )
145+ }
146+
147+ // Check if the license matches the application version data
148+ if rel .AppSlug != license .Spec .AppSlug {
149+ // if the app is different, we will not be able to provide the correct vendor supplied charts and k0s overrides
150+ return fmt .Errorf ("license app %s does not match binary app %s" , license .Spec .AppSlug , rel .AppSlug )
151+ }
152+ if rel .ChannelID != license .Spec .ChannelID {
153+ // if the channel is different, we will not be able to install the pinned vendor application version within kots
154+ // this may result in an immediate k8s upgrade after installation, which is undesired
155+ return fmt .Errorf ("license channel %s (%s) does not match binary channel %s" , license .Spec .ChannelID , license .Spec .ChannelName , rel .ChannelID )
156+ }
157+
158+ return nil
159+
160+ }
161+
121162// createK0sConfig creates a new k0s.yaml configuration file. The file is saved in the
122163// global location (as returned by defaults.PathToK0sConfig()). If a file already sits
123164// there, this function returns an error.
@@ -296,6 +337,12 @@ var installCommand = &cli.Command{
296337 return ErrNothingElseToAdd
297338 }
298339 metrics .ReportApplyStarted (c )
340+ logrus .Debugf ("checking license matches" )
341+ if err := checkLicenseMatches (c ); err != nil {
342+ err := fmt .Errorf ("unable to check license: %w" , err )
343+ metrics .ReportApplyFinished (c , err )
344+ return err
345+ }
299346 logrus .Debugf ("materializing binaries" )
300347 if err := goods .Materialize (); err != nil {
301348 err := fmt .Errorf ("unable to materialize binaries: %w" , err )
0 commit comments