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

Rolling back system token OTP logic #219

Merged
merged 2 commits into from
Nov 21, 2017
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
13 changes: 2 additions & 11 deletions app/controllers/api/base_controller/authentication.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Api
class BaseController
module Authentication
SYSTEM_TOKEN_ALLOWED_TIME_SKEW = 5.minutes
SYSTEM_TOKEN_TTL = 30.seconds

#
# REST APIs Authenticator and Redirector
Expand Down Expand Up @@ -80,8 +80,6 @@ def authenticate_with_user_token(auth_token)
end

def authenticate_with_system_token(x_miq_token)
validate_system_token_otp(x_miq_token)

@miq_token_hash = YAML.load(MiqPassword.decrypt(x_miq_token))

validate_system_token_server(@miq_token_hash[:server_guid])
Expand All @@ -106,14 +104,7 @@ def validate_system_token_server(server_guid)

def validate_system_token_timestamp(timestamp)
raise "Missing timestamp" if timestamp.blank?
raise "Invalid timestamp #{timestamp} specified" if SYSTEM_TOKEN_ALLOWED_TIME_SKEW.ago.utc > timestamp
end

def validate_system_token_otp(x_miq_token)
token_store = TokenStore.acquire("api_system_token_otp", SYSTEM_TOKEN_ALLOWED_TIME_SKEW)
token_used_timestamp = token_store.read(x_miq_token)
raise "System Token was already used at #{token_used_timestamp}" if token_used_timestamp
token_store.write(x_miq_token, Time.now.getlocal)
raise "Invalid timestamp #{timestamp} specified" if SYSTEM_TOKEN_TTL.ago.utc > timestamp
end
end
end
Expand Down
16 changes: 0 additions & 16 deletions spec/requests/authentication_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,22 +342,6 @@ def systoken(server_guid, userid, timestamp)
expect(response).to have_http_status(:ok)
expect_result_to_have_keys(ENTRYPOINT_KEYS)
end

it "authentication using a valid token succeeds only once" do
miq_token = systoken(MiqServer.first.guid, @user.userid, Time.now.utc)

get api_entrypoint_url, :headers => {Api::HttpHeaders::MIQ_TOKEN => miq_token}

expect(response).to have_http_status(:ok)
expect_result_to_have_keys(ENTRYPOINT_KEYS)

get api_entrypoint_url, :headers => {Api::HttpHeaders::MIQ_TOKEN => miq_token}

expect(response).to have_http_status(:unauthorized)
expect(response.parsed_body).to include(
"error" => a_hash_including("kind" => "unauthorized", "message" => AUTHENTICATION_ERROR)
)
end
end

context "Role Based Authorization" do
Expand Down