Защита стенда и управление секретами через OpenBao
This commit is contained in:
+1
-1
@@ -50,7 +50,7 @@ make test BASE_URL=https://localhost:8443 CA_FILE=/absolute/path/to/ca.crt
|
||||
make test-security BASE_URL=https://localhost:8443 CA_FILE=/absolute/path/to/ca.crt
|
||||
```
|
||||
|
||||
Все скрипты принимают `--ca-file`/`CA_FILE` и проверяют серверный сертификат и hostname. `--insecure` отсутствует. TLS-тест сначала проверяет рабочее доверенное соединение, затем намеренно пустой trust store и именно ошибку проверки сертификата; network timeout не засчитывается как правильный отказ. **Внутреннее mTLS, identity/authorization, OpenBao policy и hardening проверяют отдельные тесты студента** по trust matrix. Клиентский сертификат внешнему учебному REST-клиенту не требуется: mTLS находится на внутренних связях.
|
||||
Все скрипты принимают `--ca-file`/`CA_FILE` и проверяют серверный сертификат и hostname. `--insecure` отсутствует. `test-security` сначала проверяет доверенное соединение и отказ пустого trust store, затем выполняет негативные проверки user/chat/attachment ACL, запрет cross-chat attachment, 10 MiB upload limit, максимум трёх активных сессий и общий Redis-backed login limit с `429 Retry-After`. Network timeout не засчитывается как правильный TLS-отказ. **Внутреннее mTLS и OpenBao policy проверяют отдельные тесты** по trust matrix. Клиентский сертификат внешнему REST-клиенту не требуется: mTLS находится на внутренних связях.
|
||||
|
||||
## Что ещё остаётся доказать
|
||||
|
||||
|
||||
+55
-3
@@ -1,9 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Public lab7 external TLS check. Internal mTLS/policies require student tests."""
|
||||
"""Lab7 external TLS, login/session limits and user/attachment ACL checks."""
|
||||
import base64
|
||||
import ssl
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from client import Client, LAB, NoRedirect, arguments, check, run
|
||||
from client import Client, LAB, NoRedirect, ROOT, arguments, check, run
|
||||
|
||||
|
||||
def main():
|
||||
@@ -24,7 +25,58 @@ def main():
|
||||
check(isinstance(exc.reason,ssl.SSLCertVerificationError),'negative probe failed for a non-certificate reason')
|
||||
rejected = True
|
||||
check(rejected,'server unexpectedly passed validation with an empty trust store')
|
||||
print('PASS: trusted HTTPS works; untrusted CA rejected. This does NOT verify internal mTLS, OpenBao or hardening.')
|
||||
|
||||
alice,bob,eve,chat = c.bootstrap()
|
||||
chat_path = '/api/v1/chats/'+chat['id']
|
||||
|
||||
# Bearer identity wins over attacker-controlled compatibility headers.
|
||||
forged = c.call('GET','/api/v1/users/me',actor=eve,
|
||||
headers={'X-User-Id':alice['id']},schema='User')['json']
|
||||
check(forged['id']==eve['id'],'X-User-Id overrode Bearer identity')
|
||||
c.call('GET',chat_path,404,actor=eve)
|
||||
c.call('GET',chat_path+'/messages',404,actor=eve)
|
||||
c.call('POST',chat_path+'/messages',404,actor=eve,
|
||||
headers={'Idempotency-Key':'acl-outsider-message'},body={'text':'forbidden'})
|
||||
|
||||
attachment,_ = c.attachment(alice,chat)
|
||||
for suffix in ('','/content'):
|
||||
c.call('GET','/api/v1/attachments/'+attachment['id']+suffix,404,actor=eve)
|
||||
sample = (ROOT / 'tests/fixtures/sample.png').read_bytes()
|
||||
c.call('POST',chat_path+'/attachments?filename=forbidden.png',404,actor=eve,
|
||||
raw=sample,headers={'Content-Type':'image/png'})
|
||||
|
||||
second_chat = c.call('POST','/api/v1/chats',201,actor=alice,
|
||||
body={'title':'Изолированный чат','member_ids':[alice['id'],bob['id']]},
|
||||
schema='Chat')['json']
|
||||
c.call('POST','/api/v1/chats/'+second_chat['id']+'/messages',404,actor=alice,
|
||||
headers={'Idempotency-Key':'cross-chat-attachment'},
|
||||
body={'text':'','attachment_ids':[attachment['id']]})
|
||||
|
||||
# The declared request size is rejected before image decoding/storage.
|
||||
c.call('POST',chat_path+'/attachments?filename=oversized.png',413,actor=alice,
|
||||
raw=b'x'*(10*1024*1024+1),headers={'Content-Type':'image/png'})
|
||||
|
||||
# At most three active sessions are retained. Five logins fit under the
|
||||
# default per-username login window and must revoke the oldest token.
|
||||
credential = base64.b64encode((alice['registration']['username']+':'
|
||||
+alice['registration']['password']).encode()).decode()
|
||||
for _ in range(4):
|
||||
c.call('POST','/api/v1/auth/sessions',201,
|
||||
headers={'Authorization':'Basic '+credential},schema='Session')
|
||||
c.call('GET','/api/v1/users/me',401,actor=alice)
|
||||
|
||||
limited = c.user('rate_limit')
|
||||
bad = base64.b64encode((limited['registration']['username']+':wrong-password').encode()).decode()
|
||||
for _ in range(4):
|
||||
c.call('POST','/api/v1/auth/sessions',401,
|
||||
headers={'Authorization':'Basic '+bad})
|
||||
blocked = c.call('POST','/api/v1/auth/sessions',429,
|
||||
headers={'Authorization':'Basic '+bad})
|
||||
check(blocked['json']['error']['code']=='rate_limited','wrong rate-limit error code')
|
||||
retry_after = blocked['headers'].get('Retry-After','')
|
||||
check(retry_after.isdigit() and int(retry_after)>=1,'missing positive Retry-After')
|
||||
|
||||
print('PASS: trusted HTTPS, ACL/attachment isolation, session cap, upload and login limits.')
|
||||
|
||||
if __name__=='__main__':
|
||||
run(main)
|
||||
|
||||
Reference in New Issue
Block a user