Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[proxy] introduce OIDC integration types [THREESCALE-2665] #829

Merged
merged 1 commit into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/controllers/admin/api/services/proxies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def show
##~ op.parameters.add name: "error_status_no_match", description: "Status code when no mapping rule is matched.", dataType: "int", paramType: "query", required: false
##~ op.parameters.add name: "error_headers_no_match", description: "Content-Type header when no mapping rule is matched.", dataType: "string", paramType: "query", required: false
##~ op.parameters.add name: "oidc_issuer_endpoint", description: "Location of your OpenID Provider.", dataType: "string", paramType: "query", required: false
##~ op.parameters.add name: "oidc_issuer_type", description: "Type of your OpenID Provider.", dataType: "string", paramType: "query", required: false
##~ op.parameters.add name: "sandbox_endpoint", description: "Sandbox endpoint.", dataType: "string", paramType: "query", required: false
#
def update
Expand All @@ -76,7 +77,7 @@ def proxy_params
error_status_auth_failed error_status_auth_failed error_headers_auth_failed
error_status_auth_missing error_headers_auth_missing error_no_match
error_status_no_match error_headers_no_match secret_token hostname_rewrite
oauth_login_url api_test_path oidc_issuer_endpoint]
oauth_login_url api_test_path oidc_issuer_endpoint oidc_issuer_type]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add it to the documentation

##~ op.parameters.add name: "oidc_issuer_endpoint", description: "Location of your OpenID Provider.", dataType: "string", paramType: "query", required: false

params.require(:proxy).permit(permitted_params)
end

Expand Down
5 changes: 4 additions & 1 deletion app/controllers/api/integrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,10 @@ def proxy_params

basic_fields << :endpoint if @service.using_proxy_pro? || @proxy.saas_script_driven_apicast_self_managed?

basic_fields << :oidc_issuer_endpoint if provider_can_use?(:apicast_oidc)
if provider_can_use?(:apicast_oidc)
basic_fields << :oidc_issuer_endpoint
basic_fields << :oidc_issuer_type
end

params.require(:proxy).permit(*basic_fields)
end
Expand Down
13 changes: 12 additions & 1 deletion app/models/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class Proxy < ApplicationRecord

HTTP_HEADER = /\A[{}\[\]\d,.;@#~%&()?\w_"= \/\\:-]+\Z/

OIDC_ISSUER_TYPES = {
keycloak: I18n.t(:keycloak, scope: 'proxy.oidc_issuer_type').freeze,
rest: I18n.t(:rest, scope: 'proxy.oidc_issuer_type').freeze,
}.freeze

validates :api_backend, uri: { path: proc { provider_can_use?(:proxy_private_base_path) } },
non_localhost: { message: :protected_domain }

Expand Down Expand Up @@ -59,12 +64,14 @@ class Proxy < ApplicationRecord
format: { with: HTTP_HEADER }

validates :api_test_path, length: { maximum: 8192 }
validates :endpoint, :api_backend, :auth_app_key, :auth_app_id, :auth_user_key, :oidc_issuer_endpoint,
validates :endpoint, :api_backend, :auth_app_key, :auth_app_id, :auth_user_key,
:oidc_issuer_endpoint, :oidc_issuer_type,
:credentials_location, :error_auth_failed, :error_auth_missing, :authentication_method,
:error_headers_auth_failed, :error_headers_auth_missing, :error_no_match,
:error_headers_no_match, :secret_token, :hostname_rewrite, :sandbox_endpoint,
length: { maximum: 255 }

validates :oidc_issuer_type, inclusion: { in: OIDC_ISSUER_TYPES.keys.map(&:to_s), allow_blank: true }, presence: { if: ->(proxy) { proxy.oidc_issuer_endpoint.present? } }
validate :policies_config_structure

accepts_nested_attributes_for :proxy_rules, allow_destroy: true
Expand Down Expand Up @@ -142,6 +149,10 @@ def oidc_configuration
super || build_oidc_configuration(standard_flow_enabled: true)
end

def self.oidc_issuer_types
OIDC_ISSUER_TYPES.invert
end

class DeploymentStrategy
# @return Proxy
attr_reader :proxy
Expand Down
1 change: 1 addition & 0 deletions app/representers/proxy_representer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ProxyRepresenter < ThreeScale::Representer
property :lock_version

property :oidc_issuer_endpoint, if: ->(*) { oidc? }
property :oidc_issuer_type, if: ->(*) { oidc? }

class JSON < ProxyRepresenter
include Roar::JSON
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
= f.toggled_inputs 'Authentication Settings' do
- if @service.oidc?
= f.input :oidc_issuer_type, hint: true, as: :select,
collection: Proxy.oidc_issuer_types, selected: @proxy.oidc_issuer_type || Proxy.column_defaults['oidc_issuer_type']
= f.input :oidc_issuer_endpoint, hint: true, input_html: { placeholder: "https://sso.example.com/auth/realms/gateway" }
= f.inputs "OIDC Authorization flow" do
= f.semantic_fields_for :oidc_configuration do |config|
Expand Down
5 changes: 4 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ en:
hosted_proxy_endpoint: "Public Base URL"
production_endpoint: "Public Base URL"
oidc_issuer_endpoint: "OpenID Connect Issuer"
oidc_issuer_type: "OpenID Connect Issuer Type"

profile:
company_url: URL
Expand Down Expand Up @@ -1124,7 +1125,9 @@ en:
headers: "As HTTP Headers"
query: "As query parameters (GET) or body parameters (POST/PUT/DELETE)"
authorization: "As HTTP Basic Authentication"

oidc_issuer_type:
keycloak: 'Red Hat Single Sign-On'
rest: 'REST API'
formtastic:
hints:
user:
Expand Down
15 changes: 15 additions & 0 deletions db/migrate/20190530065503_add_proxies_oidc_issuer_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class AddProxiesOIDCIssuerType < ActiveRecord::Migration
def change
add_column :proxies, :oidc_issuer_type, :string, default: nil

reversible do |dir|
dir.up do
Proxy.where.not(oidc_issuer_endpoint: nil).select(:id).find_in_batches(batch_size: 10_000) do |batch|
Proxy.where(id: batch).update_all(oidc_issuer_type: 'keycloak')
end

change_column_default :proxies, :oidc_issuer_type, 'keycloak'
end
end
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20190527104222) do
ActiveRecord::Schema.define(version: 20190530065503) do

create_table "access_tokens", force: :cascade do |t|
t.integer "owner_id", limit: 8, null: false
Expand Down Expand Up @@ -1082,6 +1082,7 @@
t.integer "lock_version", limit: 8, default: 0, null: false
t.string "authentication_method", limit: 255
t.text "policies_config", limit: 65535
t.string "oidc_issuer_type", limit: 255, default: "keycloak"
end

add_index "proxies", ["service_id"], name: "index_proxies_on_service_id", using: :btree
Expand Down
1 change: 1 addition & 0 deletions test/unit/proxy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ def test_set_correct_endpoints

assert_difference proxy_changed_events.method(:count) do
@proxy.oidc_issuer_endpoint = 'http://example.com'
@proxy.oidc_issuer_type = 'keycloak'
@proxy.save!
end
end
Expand Down