Caching: Improving Rendering Time & Database Performance (ESaaS §12.6) © 2013 Armando Fox & David Patterson, all rights reserved.

Slides:



Advertisements
Similar presentations
Infosec 2012 | 25/4/12 Application Performance Monitoring Ofer MAOR CTO Infosec 2012.
Advertisements

Don’t get Stung (An introduction to the OWASP Top Ten Project) Barry Dorrans Microsoft Information Security Tools NEW AND IMPROVED!
Understand Database Security Concepts
More on SSL/TLS. Internet security: TLS TLS is one of the more prominent internet security protocols. TLS is one of the more prominent internet security.
1 Topic 1 – Lesson 3 Network Attacks Summary. 2 Questions ► Compare passive attacks and active attacks ► How do packet sniffers work? How to mitigate?
Security Issues and Challenges in Cloud Computing
Lecture 2 Page 1 CS 236, Spring 2008 Security Principles and Policies CS 236 On-Line MS Program Networks and Systems Security Peter Reiher Spring, 2008.
It’s always better live. MSDN Events Security Best Practices Part 2 of 2 Reducing Vulnerabilities using Visual Studio 2008.
Information Networking Security and Assurance Lab National Chung Cheng University The Ten Most Critical Web Application Security Vulnerabilities Ryan J.W.
It’s always better live. MSDN Events Securing Web Applications Part 1 of 2 Understanding Threats and Attacks.
Lesson 11-Virtual Private Networks. Overview Define Virtual Private Networks (VPNs). Deploy User VPNs. Deploy Site VPNs. Understand standard VPN techniques.
CMSC 414 Computer and Network Security Lecture 19 Jonathan Katz.
Analysis and Performance Information Systems 337 Prof. Harry Plantinga.
 Proxy Servers are software that act as intermediaries between client and servers on the Internet.  They help users on private networks get information.
D ATABASE S ECURITY Proposed by Abdulrahman Aldekhelallah University of Scranton – CS521 Spring2015.
Martin Kruliš by Martin Kruliš (v1.0)1.
CSCI 6962: Server-side Design and Programming
Ruby on Rails CSCI 6314 David Gaspar Jennifer Garcia Avila.
ISOM MIS3150 Data and Info Mgmt Database Security Arijit Sengupta.
Networks and Security. Types of Attacks/Security Issues  Malware  Viruses  Worms  Trojan Horse  Rootkit  Phishing  Spyware  Denial of Service.
Lecture 18 Page 1 CS 111 Online Design Principles for Secure Systems Economy Complete mediation Open design Separation of privileges Least privilege Least.
Cosc 4765 Server side Web security. Web security issues From Cenzic Vulnerability report
Principles of Computer Security: CompTIA Security + ® and Beyond, Third Edition © 2012 Principles of Computer Security: CompTIA Security+ ® and Beyond,
CSCI 6962: Server-side Design and Programming Secure Web Programming.
Lecture 14 – Web Security SFDV3011 – Advanced Web Development 1.
1-Vulnerabilities 2-Hackers 3-Categories of attacks 4-What a malicious hacker do? 5-Security mechanisms 6-HTTP Web Servers 7-Web applications attacks.
© All rights reserved. Zend Technologies, Inc. PHP Security Kevin Schroeder Zend Technologies.
November 13, 2008 Ohio Information Security Forum Attack Surface of Web Applications James Walden Northern Kentucky University
SEC835 Practical aspects of security implementation Part 1.
Security Scanners Mark Shtern. Popular attack targets Web – Web platform – Web application Windows OS Mac OS Linux OS Smartphone.
SE-2840 Dr. Mark L. Hornick1 Web Application Security.
All Input is Evil (Part 1) Introduction Will not cover everything Healthy level of paranoia Use my DVD Swap Shop application (week 2)
Module 10 Administering and Configuring SharePoint Search.
Analysis of SQL injection prevention using a filtering proxy server By: David Rowe Supervisor: Barry Irwin.
October 3, 2008IMI Security Symposium Application Security through a Hacker’s Eyes James Walden Northern Kentucky University
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
Web Applications Testing By Jamie Rougvie Supported by.
Crash Course in Web Hacking
Lecture 16 Page 1 CS 236 Online Web Security CS 236 On-Line MS Program Networks and Systems Security Peter Reiher.
Lecture slides prepared for “Computer Security: Principles and Practice”, 3/e, by William Stallings and Lawrie Brown, Chapter 1 “Overview”. © 2016 Pearson.
Database Security. Multi-user database systems like Oracle include security to control how the database is accessed and used for example security Mechanisms:
Deconstructing API Security
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 9 1COMP9321, 15s2, Week.
Web Security Lesson Summary ●Overview of Web and security vulnerabilities ●Cross Site Scripting ●Cross Site Request Forgery ●SQL Injection.
Database Security Cmpe 226 Fall 2015 By Akanksha Jain Jerry Mengyuan Zheng.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
ASP.NET 2.0 Security Alex Mackman CM Group Ltd
SlideSet #20: Input Validation and Cross-site Scripting Attacks (XSS) SY306 Web and Databases for Cyber Operations.
Lecture 19 Page 1 CS 236 Online 6. Application Software Security Why it’s important: –Security flaws in applications are increasingly the attacker’s entry.
Web Security (cont.) 1. Referral issues r HTTP referer (originally referrer) – HTTP header that designates calling resource  Page on which a link is.
ArcGIS for Server Security: Advanced
Building Secure ColdFusion Applications
Caching: Improving Rendering Time & Database Performance (ESaaS §12.6)
TMG Client Protection 6NPS – Session 7.
Web Application Vulnerabilities, Detection Mechanisms, and Defenses
Security: Exploits & Countermeasures
Security: Exploits & Countermeasures
Secure Sockets Layer (SSL)
Cross-Site Forgery
OPERATING SYSTEMS CS 3502 Fall 2017
Using SSL – Secure Socket Layer
Security.
Security: Exploits & Countermeasures
CS5123 Software Validation and Quality Assurance
Security: Exploits & Countermeasures
Security: Exploits & Countermeasures
Designing IIS Security (IIS – Internet Information Service)
6. Application Software Security
Security: Attacks & Countermeasures
Presentation transcript:

Caching: Improving Rendering Time & Database Performance (ESaaS §12.6) © 2013 Armando Fox & David Patterson, all rights reserved

The Fastest Database is the One You Don’t Use Caching: Avoid touching database if answer to a query hasn’t changed 1.Identify what to cache –whole view: page & action caching –parts of view: fragment caching with partials 2.Invalidate (get rid of) stale cached versions when underlying DB changes 2

Cache Flow

Page & Action Caching When: output of entire action can be cached –Page caching bypasses controller action caches_page :index –Action caching runs filters first Caveat: caching based on page URL without optional "?" parameters! /movies/index?rating=PG = movies/index /movies/index/rating/PG ≠ movies/index Pitfall: don’t mix filter & non-filter code paths in same action! 4

Example Bad: caches_page :index def index if logged_in?... else redirect_to login_path end 5 Better: caches_page :public_index caches_action :logged_in_index before_filter :check_logged_in, :only => 'logged_in_index' def public_index... end def logged_in_index... end

Fragment Caching for Views Caches HTML resulting from rendering part of a page (e.g. partial) - cache "movies_with_ratings" do = render :collection How do we detect when cached versions no longer match database? Sweepers use Observer design pattern to separate expiration logic from rest of app 6

How Much Does Caching Help? With ~1K movies and ~100 reviews/movie in RottenPotatoes on Heroku, heroku logs shows: Can serve 8X to 21X more users with same number of servers if caching used

8 END

(ii) & (iii) (iii) only (i), (ii) and (iii) (i) & (iii) ☐ ☐ ☐ ☐ 9 Under-17 visitors to RottenPotatoes shouldn’t see NC-17 movies in any listing. A controller filter exists that can determine if a user is under 17. What kinds of caching would be appropriate: i) Page ii) Action iii) Fragment

10 END

Avoiding Abusive Queries (ESaaS §12.7) © 2013 Armando Fox & David Patterson, all rights reserved

Be Kind to the Database Outgrowing single-machine database => big investment: sharding, replication, etc. Alternative: find ways to relieve pressure on database so can stay in “PaaS-friendly” tier 1.Use caching to reduce number of database accesses 2.Avoid “n+1 queries” problem in Associations 3.Use indices judiciously

N+1 Queries Problem Problem: you are doing n+1 queries to traverse an association, rather than 1 query Solution: bullet gem can help you find these Lesson: all abstractions eventually leak!

Eager Loading Naive = movie.where( … ) reviews May be = movie.where( … do |review| # reviews are already loaded!

Indices Speeds up access when searching DB table by column other than primary key –e.g. Movie.where("rating = 'PG'") Similar to using a hash table –alternative is table scan - bad! –even bigger win if attribute is unique-valued Why not index every column? –takes up space –all indices must be updated when table updated

What to Index? Foreign key columns, e.g. movie_id field in Reviews table –why? Columns that appear in where() clauses of ActiveRecord queries Columns on which you sort Use rails_indexes gem (on GitHub) to help identify missing indices (and unnecessary ones!)

How Much Does Indexing Help?

18 END

reviews.movie_id reviews.moviegoer_id moviegoers.review_id movies.review_id ☐ ☐ ☐ ☐ 19 Suppose Movie has many Moviegoers through Reviews. Which foreign-key index would MOST help speed up the query fans

has_many :through  moviegoer: has_many :reviews has_many :movies, :through => :reviews  movie: has_many :reviews has_many :moviegoers, :through => :reviews  reviews: belongs_to :moviegoer belongs_to :movie reviews moviegoer_id movie_id... movies id... moviegoers id

21 END

Defending Customer Data (ESaaS §12.8) © 2013 Armando Fox & David Patterson, all rights reserved

Common Attacks on the App 1.Eavesdropping 2.Man-in-the-middle/Session hijack 3.SQL injection 4.Cross-site request forgery (CSRF) 5.Cross-site scripting (XSS) 6.Mass-assignment of sensitive attributes …more in book

SSL (Secure Sockets Layer) Idea: encrypt HTTP traffic to foil eavesdroppers Problem: to create a secure channel, two parties need to share a secret first But on the Web, the two parties don’t know each other Solution: public key cryptography (Rivest, Shamir, & Adelman, 2002 Turing Award)

What SSL Does, and Doesn’t Each principal has a key of 2 matched parts –public part: everyone can know it –private part: principal keeps secret –given one part, cannot deduce the other Key mechanism: encryption by one key requires decryption by the other –If a message can be decrypted with Bob’s public key, then Bob must have created (“signed”) it –If I use Bob’s public key to create a message, only Bob can read it

How SSL Works (Simplified) 1.Bob.com proves identity to CA 2.CA uses its private key to create a “cert” tying this identity to domain name “bob.com” 3.Cert is installed on Bob.com’s server 4.Browser visits 5.CA’s public keys built into browser, so can check if cert matches hostname 6.Diffie-Hellman key exchange is used to bootstrap an encrypted channel for further communication Use Rails force_ssl method to force some or all actions to use SSL

What It Does and Doesn’t Do Assures browser that bob.com is legit Prevents eavesdroppers from reading HTTP traffic between browser & bob.com Creates additional work for server! DOES NOT: ✖ Authenticate user to server ✖ Protect sensitive data after it reaches server ✖ Protect server from other server attacks ✖ Protect browser from malware if server is evil

SQL Injection View: = text_field_tag 'name' App: Moviegoer.where("name='#{params[:name]}'") Evil user fills in: BOB'); DROP TABLE moviegoers; -- Executes this SQL query: SELECT * FROM moviegoers WHERE (name='BOB'); DROP TABLE moviegoers; --' Solution: Moviegoer.where("name=?", params[:name]) xkcd.com/327

Cross-Site Request Forgery 1.Alice logs into bank.com, now has cookie 2.Alice goes to blog.evil.com 3.Page contains: <img src=" 4.evil.com harvests Alice’s personal info Solutions: (weak) check Referer field in HTTP header (strong) include session nonce with every request –c–csrf_meta_tags in layouts/application.html.haml –p–protect_from_forgery in A pplicationController –R–Rails form helpers automatically include nonce in forms

30 END

(i) & (ii) only (ii) & (iii) only (i), (ii) & (iii) (i) only ☐ ☐ ☐ ☐ 31 If a site has a valid SSL certificate from a trusted CA, which of the following is true: i) The site is probably not “masquerading” as an impostor of a real site ii) CSRF + SQL injection are harder to mount against it iii) Your data is secure once it reaches the site

32 END

Plan-And-Document Perspective on Performance, Releases, Reliability and Security (Engineering Software as a Service §12.10) 33 © 2013 Armando Fox & David Patterson, all rights reserved

P&D on the 4 Issues? Does Plan-and-Document address performance issues? Anything special about Plan-and-Document releases? P&D Standards for Quality? Are the reliability and security challenges similar in Plan-and-Document? Can unreliability lower security? 34

P&D and Performance Like reliability and security, performance considered a non-functional requirement –Can be part of acceptance tests Plan-and-document lifecycles ignore performance because –Performance optimizations often excuse for bad SW engr practice –Covered in other books/courses 35

P&D and Release Management Special case of configuration management P&D releases include everything: code, configuration files, data & documentation P&D releases number scheme: e.g., Rails version –.12 is minor release –.2 is major release –3 so large a release that it can break APIs, must re-port app 36

P&D and Reliability Dependability via redundancy –Guideline: no single point of failure How much redundancy can customer afford? Mean Time To Failure (MTTF) includes SW & operators as well as HW Unavailability ≈ Mean Time To Repair/MTTF –Improving MTTR may be easier than MTTF, but can try to improve both MTTR & MTTF 37

P&D and Processes to Improve SW P&D assumption is can improve SW development process of organization => More reliable SW product –Record all aspects of project to see what can improve Get ISO 9001 standard if a company has: 1. Process in place 2. Method to see if process is followed 3. Records results to improve process –Approval for process, not quality of resulting code 38

ISO

P&D and Security Reliability relies on probabilities, but security must defend against intelligent opponents –Common Vulnerabilities and Exposures database list typical attacks: cvedetails.comcvedetails.com Some reliability improving techniques prevent attacks: –Buffer overflows, arithmetic overflows, data races Penetration tests via tiger team can test security 40

3 Security Principles 1.Least privilege: a user or software component should be given no more privilege - that is, no further access information and resources - than what is necessary to perform its assigned task –“need-to-know” principle for classified information 41

3 Security Principles 2.Fail-safe defaults: unless a user or software component is given explicit access to an object, it should be denied access to the object –Default should be denial of access 3. Psychological acceptability: protection mechanism should not make the app harder to use than if no protection –Needs to be easy to use so that the security mechanisms are routinely followed 42

43 END

Not checking buffer limits could violate the security principle of least privilege Not removing data races could violate the security principle of psychological acceptability None are false; all are true Improper initialization of data could violate the security principle of fail-safe defaults 44 Which statement regarding reliability and security is most likely FALSE?

45 END

Fallacies, Pitfalls & Concluding Remarks (ESaaS § ) © 2013 Armando Fox & David Patterson, all rights reserved

Optimizing Prematurely or Without Measurements Speed is a feature that users expect –99%ile (e.g.), not “average” Horizontal scaling >> per-machine performance, but lots of ways things can slow down Monitoring is your friend: measure twice, cut once See “Scaling Rails Screencasts” on Youtube 47

“Mine is a 3-Tier App on Cloud Computing, So It Will Scale” Database is particularly hard to scale –Even if you do, still want to get “expensive” operations out of the way of your SLO One help: cache at many levels –Whole page, fragment, query –Cache expiration is a crosscutting concern –Rails support for crosscutting concerns allows you to specify it declaratively Use PaaS for as long as you can 48

“My Small Site Isn’t a Target” Hackers may be after your users, not your data Like performance, security is a crosscutting concern - hard to add after the fact Stay current with best practices and tools – you’re unlikely to do better by rolling your own Prepare for catastrophe: keep regular backups of site and database

50 END

Some queries are unusually slow because you’re sharing DB with other apps Some views take unusually long to render in certain browsers (eg, due to JavaScript) It could be any of these/Not enough information Not enough Heroku “dynos”, so requests occasionally get “backed up” ☐ ☐ ☐ ☐ 51 Your users are sporadically complaining that your site is slow, yet New Relic reports low traffic levels and low CPU utilization. What is the likely cause?

52 END