|
| 1 | +package convert |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/kong/go-database-reconciler/pkg/cprint" |
| 5 | + "github.com/kong/go-database-reconciler/pkg/file" |
| 6 | + "github.com/kong/go-kong/kong" |
| 7 | +) |
| 8 | + |
| 9 | +// hideCredentialsPlugins is the list of auth plugins where hide_credentials |
| 10 | +// default changed from false to true in Kong Gateway 3.14. |
| 11 | +var hideCredentialsPlugins = map[string]bool{ |
| 12 | + keyAuthPluginName: true, |
| 13 | + keyAuthEncPluginName: true, |
| 14 | + basicAuthPluginName: true, |
| 15 | + hmacAuthPluginName: true, |
| 16 | + ldapAuthPluginName: true, |
| 17 | + oauth2PluginName: true, |
| 18 | + oauth2IntrospectionPluginName: true, |
| 19 | + vaultAuthPluginName: true, |
| 20 | + ldapAuthAdvancedPluginName: true, |
| 21 | +} |
| 22 | + |
| 23 | +// sslVerifyPlugins is the list of plugins where ssl_verify default |
| 24 | +// changed from false to true in Kong Gateway 3.14 (due to the global |
| 25 | +// tls_certificate_verify changing from off to on). |
| 26 | +var sslVerifyPlugins = map[string]bool{ |
| 27 | + acePluginName: true, |
| 28 | + acmePluginName: true, |
| 29 | + aiAwsGuardrailPluginName: true, |
| 30 | + aiAzureContentSafetyPluginName: true, |
| 31 | + aiLlmAsJudgePluginName: true, |
| 32 | + aiProxyAdvancedPluginName: true, |
| 33 | + aiRagInjectorPluginName: true, |
| 34 | + aiRateLimitingAdvancedPluginName: true, |
| 35 | + aiRequestTransformerPluginName: true, |
| 36 | + aiResponseTransformerPluginName: true, |
| 37 | + aiSemanticCachePluginName: true, |
| 38 | + aiSemanticPromptGuardPluginName: true, |
| 39 | + aiSemanticResponseGuardPluginName: true, |
| 40 | + awsLambdaPluginName: true, |
| 41 | + azureFunctionsPluginName: true, |
| 42 | + basicAuthPluginName: true, |
| 43 | + confluentPluginName: true, |
| 44 | + confluentConsumePluginName: true, |
| 45 | + datakitPluginName: true, |
| 46 | + forwardProxyPluginName: true, |
| 47 | + graphqlProxyCacheAdvancedPluginName: true, |
| 48 | + graphqlRateLimitingAdvancedPluginName: true, |
| 49 | + headerCertAuthPluginName: true, |
| 50 | + httpLogPluginName: true, |
| 51 | + jwtSignerPluginName: true, |
| 52 | + kafkaConsumePluginName: true, |
| 53 | + kafkaLogPluginName: true, |
| 54 | + kafkaUpstreamPluginName: true, |
| 55 | + ldapAuthPluginName: true, |
| 56 | + ldapAuthAdvancedPluginName: true, |
| 57 | + mtlsAuthPluginName: true, |
| 58 | + opaPluginName: true, |
| 59 | + openidConnectPluginName: true, |
| 60 | + proxyCacheAdvancedPluginName: true, |
| 61 | + rateLimitingPluginName: true, |
| 62 | + rateLimitingAdvancedPluginName: true, |
| 63 | + requestCalloutPluginName: true, |
| 64 | + responseRateLimitingPluginName: true, |
| 65 | + samlPluginName: true, |
| 66 | + serviceProtectionPluginName: true, |
| 67 | + tcpLogPluginName: true, |
| 68 | + upstreamOauthPluginName: true, |
| 69 | +} |
| 70 | + |
| 71 | +func updatePluginsFor314(content *file.Content) { |
| 72 | + for idx := range content.Plugins { |
| 73 | + plugin := &content.Plugins[idx] |
| 74 | + updateLegacyPluginConfigFor314(plugin) |
| 75 | + } |
| 76 | + |
| 77 | + for _, service := range content.Services { |
| 78 | + for _, plugin := range service.Plugins { |
| 79 | + updateLegacyPluginConfigFor314(plugin) |
| 80 | + } |
| 81 | + |
| 82 | + for _, route := range service.Routes { |
| 83 | + for _, plugin := range route.Plugins { |
| 84 | + updateLegacyPluginConfigFor314(plugin) |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + for _, route := range content.Routes { |
| 90 | + for _, plugin := range route.Plugins { |
| 91 | + updateLegacyPluginConfigFor314(plugin) |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + for _, consumer := range content.Consumers { |
| 96 | + for _, plugin := range consumer.Plugins { |
| 97 | + updateLegacyPluginConfigFor314(plugin) |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + for _, consumerGroup := range content.ConsumerGroups { |
| 102 | + for _, plugin := range consumerGroup.Plugins { |
| 103 | + updateLegacyPluginConfigFor314(&file.FPlugin{ |
| 104 | + Plugin: kong.Plugin{ |
| 105 | + ID: plugin.ID, |
| 106 | + Name: plugin.Name, |
| 107 | + Config: plugin.Config, |
| 108 | + }, |
| 109 | + }) |
| 110 | + } |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +func updateLegacyPluginConfigFor314(plugin *file.FPlugin) { |
| 115 | + if plugin == nil || plugin.Name == nil { |
| 116 | + return |
| 117 | + } |
| 118 | + |
| 119 | + pluginName := *plugin.Name |
| 120 | + |
| 121 | + // Initialize config map if nil |
| 122 | + if plugin.Config == nil { |
| 123 | + plugin.Config = kong.Configuration{} |
| 124 | + } |
| 125 | + |
| 126 | + // Handle hide_credentials default change (false -> true) |
| 127 | + if hideCredentialsPlugins[pluginName] { |
| 128 | + if _, exists := plugin.Config["hide_credentials"]; !exists { |
| 129 | + plugin.Config["hide_credentials"] = false |
| 130 | + cprint.UpdatePrintf( |
| 131 | + "Plugin '%s': setting hide_credentials to false "+ |
| 132 | + "(old default, 3.14 defaults to true)\n", pluginName) |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + // Handle ssl_verify default change (false -> true) |
| 137 | + if sslVerifyPlugins[pluginName] { |
| 138 | + if _, exists := plugin.Config["ssl_verify"]; !exists { |
| 139 | + plugin.Config["ssl_verify"] = false |
| 140 | + cprint.UpdatePrintf( |
| 141 | + "Plugin '%s': setting ssl_verify to false "+ |
| 142 | + "(old default, 3.14 defaults to true)\n", pluginName) |
| 143 | + } |
| 144 | + } |
| 145 | +} |
0 commit comments